2011-11-14 95 views
0

我想了解Caliburn.Micro如何与Windows Phone(和一般的MVVM)协同工作,所以我创建了一个基本的Windows Phone应用程序,安装了Caliburn.Micro NuGet package(v1.2.0 - 最新版本现在),并遵循这里和那里的几条指令。所以,我结束了:Can not Make Caliburn.Micro With Windows Phone

WMAppManifest.xml

<DefaultTask Name ="_default" NavigationPage="Views/HomeView.xaml"/> 

框架/ AppBootstrapper.cs

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Windows; 
using Caliburn.Micro; 
using MyCaliburn.PhoneUI.ViewModels; 

namespace MyCaliburn.PhoneUI.Framework 
{ 
    public class AppBootstrapper : PhoneBootstrapper 
    { 
     PhoneContainer container; 

     protected override void Configure() 
     { 
      container = new PhoneContainer(RootFrame); 
      container.RegisterPhoneServices(); 
      container.Singleton<HomeViewModel>(); 
     } 

     protected override void OnUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
     { 
      if (Debugger.IsAttached) 
      { 
       Debugger.Break(); 
       e.Handled = true; 
      } 
      else 
      { 
       MessageBox.Show("An unexpected error occured, sorry about the troubles.", "Oops...", MessageBoxButton.OK); 
       e.Handled = true; 
      } 

      base.OnUnhandledException(sender, e); 
     } 

     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); 
     } 
    } 
} 

的ViewModels/HomeViewModel.cs

using Caliburn.Micro; 

namespace MyCaliburn.PhoneUI.ViewModels 
{ 
    public class HomeViewModel : Screen 
    { 
     public HomeViewModel() 
     { 
      //DisplayName = "Home"; 
     } 
    } 
} 

查看/ HomeView.xaml.cs(XAML中页是默认窗口电话纵向页面)

using Microsoft.Phone.Controls; 

namespace MyCaliburn.PhoneUI.Views 
{ 
    public partial class HomeView : PhoneApplicationPage 
    { 
     public HomeView() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

的App.xaml

<Application 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="MyCaliburn.PhoneUI.App" 
    xmlns:Framework="clr-namespace:MyCaliburn.PhoneUI.Framework"> 

    <!--Application Resources--> 
    <Application.Resources> 
     <Framework:AppBootstrapper x:Key="bootstrapper" /> 
    </Application.Resources> 

</Application> 

App.xaml.cs

using System.Windows; 

namespace MyCaliburn.PhoneUI 
{ 
    public partial class App : Application 
    { 
     /// <summary> 
     /// Constructor for the Application object. 
     /// </summary> 
     public App() 
     { 
      // Standard Silverlight initialization 
      InitializeComponent(); 
     } 
    } 
} 

现在,当我打F5时,应用程序阳离子运行并退出而不显示任何页面或异常,并且不会触及我所坐的任何断点。

任何人都可以告诉我什么是我的代码中防止应用程序运行丢失?

在此先感谢。

回答

3

很多时候,当我结束了一个无法启动的应用程序时 - 事实证明,由于某些重构,App类不再是启动对象。右键单击解决方案资源管理器中的项目,转到属性/应用程序并确保启动对象设置正确。

+0

我有一种感觉,我错过了一件非常愚蠢的事情:)你是对的,启动对象设置不正确。 – TheBlueSky