1

编辑:看来我终于让它工作了。我问了我之前提到的那篇文章的作者,他说这是一个已知问题。他还给了 mi 一个解决方法(在帖子下方的评论中),所以我认为这个问题已经结束。但是感谢大家花时间解决我的问题:)


我正在尝试使用 Caliburn Micro 框架学习 MVVM,但我从一开始就遇到了问题。我正在关注教程,并且在 App.xaml 中得到了这样的代码:

<Application
x:Class="Caliburn.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:caliburnMicro="clr-namespace:Caliburn">
<!--Application Resources-->
    <Application.Resources>
        <caliburnMicro:Bootstrapper x:Key="bootstrapper" />
    </Application.Resources>
</Application>

但我得到一个错误:

名称空间“clr-namespace:Caliburn”中不存在名称“Bootstrapper”。

我从 NuGet 存储库获得了 Caliburn Micro 1.5.2。任何想法表示赞赏...

我的引导程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Micro;

namespace Caliburn
{
public class Bootstrapper : PhoneBootstrapper
{
    PhoneContainer container;

    protected override void Configure()
    {
        container = new PhoneContainer();

        container.RegisterPhoneServices(RootFrame);
        //container.PerRequest<MainPageViewModel>();

        AddCustomConventions();
    }

    static void AddCustomConventions()
    {
        //ellided  
    }

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

3 回答 3

4

您应该定义自己的 Bootstrapper 类型,该类型派生自 Caliburn.Micro 引导程序类型之一。然后,您的应用程序资源中的资源应该是此引导程序的一个实例。

学习时最简单的选择是使用Caliburn.Micro.Start NuGet 包,并查看它的引导程序实现。该文档还描述了应在 App.xaml 文件中使用的标记。

于 2013-07-09T12:57:38.490 回答
1

我认为每个人都感到困惑,因为您命名了自己的命名空间caliburn,所以他们认为您正在尝试创建框架引导程序的实例,所以我建议更改您的命名约定。用我们的方式,而不是将引导程序直接放入应用程序资源中,尝试将其放入资源字典中,如下所示:

<Application
x:Class="Caliburn.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:caliburnMicro="clr-namespace:Caliburn">
<!--Application Resources-->
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:Bootstrapper x:Key="bootstrapper" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
于 2013-07-09T14:37:57.960 回答
0

我有同样的问题,很容易解决。您需要在 Bootstrapper 类和此方法集中覆盖方法 OnStart ,这是您的根视图。

protected override void OnStartup(object sender, StartupEventArgs e)
{
    DisplayRootViewFor<ViewModels.ShellVM>();
}
于 2017-09-22T09:15:44.753 回答