Skip to main content
 首页 » 编程设计

c#之Caliburn.Micro 在 App.xaml 的命名空间中没有 "Bootstrapper"

2024年02月13日25langtianya

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


我正在尝试使用 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> 

但是我得到一个错误:

The name "Bootstrapper" does not exist in the namespace "clr-namespace:Caliburn".

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

我的 Bootstrap :

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

请您参考如下方法:

您应该定义自己的 Bootstrapper 类型,该类型派生自 Caliburn.Micro bootstrapper 类型之一。你的应用程序资源中的资源应该是这个 Bootstrap 的一个实例。

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