- Начните с стандартного «пустого» проекта Windows Phone App (Windows Phone 8). Назовем это
BlackAdder
для удовольствия. - Добавить Caliburn.Micro из NuGet
- Move
MainPage.xaml
подкаталогViews
и создать соответствующий ViewModel вViewModels\MainPageViewModel.cs
- Фикс пространство имен для
MainPage
кBlackadder.Views
в обоих.xaml
и.xaml.cs
файлов -
<Application x:Class="BlackAdder.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:local="clr-namespace:BlackAdder"> <Application.Resources> <local:Bootstrapper x:Key="bootstrapper"/> </Application.Resources> </Application>
Обновление
App.xaml.cs
public partial class App : Application { public static PhoneApplicationFrame RootFrame { get; private set; } public App() { InitializeComponent(); // Show graphics profiling information while debugging. if (Debugger.IsAttached) { ... } } }
Создать
Bootstrapper.cs
public class Bootstrapper : PhoneBootstrapper { private PhoneContainer container; protected override void Configure() { container = new PhoneContainer(); container.RegisterPhoneServices(RootFrame); container.PerRequest<MainPageViewModel>(); AddCustomConventions(); } protected static void AddCustomConventions() { } protected override object GetInstance(Type service, string key) { return container.GetInstance(service, key); } protected override IEnumerable<object> GetAllInstances(Type service) { return container.GetAllInstances(service); } protected override void BuildUp(object instance) { container.BuildUp(instance); } }
При запуске приложения, он выходит из строя в очень странное место.
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll
Additional information: Exception has been thrown by the target of an invocation.
Внутреннего исключения нет, а трассировка стека (по-видимому) бесполезна.
System.Windows.ni.dll!System.Windows.Threading.DispatcherOperation.Invoke()
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority priority)
System.Windows.ni.dll!System.Windows.Threading.Dispatcher.OnInvoke(object context)
System.Windows.ni.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args)
System.Windows.RuntimeHost.ni.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam* pParams, System.Windows.Hosting.NativeMethods.ScriptParam* pResult)