在.xaml.cs中创建支持代码时在.xaml中创建时出错
我遇到了一个奇怪的问题,在App.xaml中创建派生自Caliburn.Micro.Autofac.AutofacBootstrapper的类失败,生成错误: XML命名空间“clr命名空间:TestProject”中不存在标记“Bootstrapper” 但如果我只是在App.xaml.cs中创建引导程序,一切都会正常工作 下面的代码显示了我可以做些什么来让事情顺利进行。如果我在App.xaml中取消对引导程序的注释,并在App.xaml.cs中注释掉引导程序,我将得到生成错误 这两者有什么不同 Intellisense对App.xaml中的引导程序很满意。我只在构建时收到错误 这是我的App.xaml在.xaml.cs中创建支持代码时在.xaml中创建时出错,xaml,silverlight-5.0,autofac,caliburn.micro,Xaml,Silverlight 5.0,Autofac,Caliburn.micro,我遇到了一个奇怪的问题,在App.xaml中创建派生自Caliburn.Micro.Autofac.AutofacBootstrapper的类失败,生成错误: XML命名空间“clr命名空间:TestProject”中不存在标记“Bootstrapper” 但如果我只是在App.xaml.cs中创建引导程序,一切都会正常工作 下面的代码显示了我可以做些什么来让事情顺利进行。如果我在App.xaml中取消对引导程序的注释,并在App.xaml.cs中注释掉引导程序,我将得到生成错误 这两者有什么不
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestProject"
x:Class="TestProject.App"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<!--
<local:Bootstrapper x:Key="Bootstrapper"/>
-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
这里是Bootsteapper.cs
namespace TestProject
{
public class Bootstrapper : AutofacBootstrapper<MainPageViewModel>
{
public Bootstrapper()
{
base.ConfigureBootstrapper();
EnforceNamespaceConvention = false;
ViewModelBaseType = typeof(IShell);
}
protected override void ConfigureContainer(Autofac.ContainerBuilder builder)
{
builder.RegisterType<MainPageViewModel>();
base.ConfigureContainer(builder);
}
}
}
名称空间测试项目
{
公共类引导程序:AutofacBootstrapper
{
公共引导程序()
{
base.ConfigureBootstrapper();
EnforceNamespaceConvention=false;
ViewModelBaseType=typeof(IShell);
}
受保护的覆盖无效配置容器(Autofac.ContainerBuilder生成器)
{
RegisterType();
基本配置容器(生成器);
}
}
}
您是否尝试将引导程序设置为超出合并词典的范围
<Application.Resources>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Assembly;component/OtherResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
好吧,这很奇怪,但我有两件事要问你,第一件事是你从哪里得到AutofacBootstrapper的,第二件事可能是引导程序本身可能没有正确编译?我使用NuGet获得了Caliburn.Micro.Autofac(1.5.0.0)的最新版本,它还引入了依赖项Caliburn.Micro(1.4.1.0)和Autofac(2.6.3.862)。奇怪的是,当从后面的代码实例化时,它工作正常。它似乎确实与Cliburn有关。从xaml文件中微实例化一个空的DummyClass可以正常工作。nuget包和/或源项目配置似乎有问题。我下载了代码并从源代码进行编译,App.xaml工作正常,但我没有获得任何intellisense。我需要把.cs文件放到一个新的项目中,然后自己编译来修复它。
<Application.Resources>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper" />
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Assembly;component/OtherResource.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>