【问题标题】:Can't Make Caliburn.Micro Work With Windows Phone无法使 Caliburn.Micro 与 Windows Phone 一起使用
【发布时间】:2011-12-28 22:53:32
【问题描述】:

我试图了解Caliburn.Micro 如何与 Windows Phone(以及一般的 MVVM)一起工作,所以我创建了一个基本的 Windows Phone 应用程序,安装了Caliburn.Micro NuGet package(v1.2.0 - 目前最新版本)并遵循了少数几个这里和那里的说明。所以,我最终得到:

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

View/HomeView.xaml.cs(XAML 页面是默认的 Window Phone 纵向页面)

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 时,应用程序会运行并退出,不会显示任何页面或异常,也不会遇到我所在的任何断点。

谁能告诉我我的代码中缺少什么导致应用程序无法运行?

提前致谢。

【问题讨论】:

    标签: windows-phone-7 mvvm caliburn.micro


    【解决方案1】:

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

    【讨论】:

    • 我感觉我错过了一件非常愚蠢的事情:)你是对的,启动对象没有正确设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-09
    相关资源
    最近更新 更多