Caliburn.Micro在App.xaml的命名空间中没有“Bootstrapper”

时间:2013-07-09 12:55:26

标签: c# windows-phone-7 windows-phone-8 windows-phone caliburn.micro

编辑:似乎我终于让它发挥作用了。我问过我之前提到过的那篇文章的作者,他说这是一个众所周知的问题。他还给了mi一个解决方法(在帖子下方的评论中),所以我认为这个问题是封闭的。但感谢大家花时间处理我的问题:)


我正在尝试使用Caliburn Micro框架学习MVVM,但我从一开始就遇到了问题。我正在关注this教程,我在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>

但我收到了一个错误:

  

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

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

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分: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>

答案 2 :(得分:-1)

我遇到了同样的问题而且很容易解决。您需要在Bootstrapper类中以及在此方法集中覆盖方法OnStart,这是您的根视图。

protected override void OnStartup(object sender, StartupEventArgs e)
{
    DisplayRootViewFor<ViewModels.ShellVM>();
}