Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Caliburn.微型罐';t匹配来自不同部件的视图和视图模型_C#_.net_Mvvm_Caliburn.micro - Fatal编程技术网

C# Caliburn.微型罐';t匹配来自不同部件的视图和视图模型

C# Caliburn.微型罐';t匹配来自不同部件的视图和视图模型,c#,.net,mvvm,caliburn.micro,C#,.net,Mvvm,Caliburn.micro,我刚从Caliburn.Micro开始 我试图引导我的简单示例解决方案,将ShellView(usercontrol)放在Test.App程序集中,将ShellViewModel放在Test.ViewModel程序集中 我得到的是一个带有以下文本的窗口:“找不到Caliburn.Test.ViewModel.ShellViewModel的视图” 但是,如果我将ViewModel移动到.App程序集,它就可以完美地工作 这是Caliburn.Micro.Test程序集中的引导程序(可执行): 你能

我刚从Caliburn.Micro开始

我试图引导我的简单示例解决方案,将ShellView(usercontrol)放在Test.App程序集中,将ShellViewModel放在Test.ViewModel程序集中

我得到的是一个带有以下文本的窗口:“找不到Caliburn.Test.ViewModel.ShellViewModel的视图”

但是,如果我将ViewModel移动到.App程序集,它就可以完美地工作

这是Caliburn.Micro.Test程序集中的引导程序(可执行):

你能帮我解决我的问题吗?
谢谢D

通过覆盖引导程序中的
SelectAssemblies
,检查您是否已为CM选择了程序集

此处的文档有一个示例:

protectedoverride IEnumerable

那就跟着做吧。如果要直接跳到命名约定,请查看此特定页面:


多亏了这篇文章,问题才得以解决


编辑:由于您将您的回复与我的整合,我将接受的答案更改为您的。

您是否覆盖了
选择程序集
?您需要为CM提供所有包含视图的程序集。您如何使用“CM”mena?无论如何,我读到assemly需要搜索视图,但是视图在引导程序的同一个程序集中,视图模型在另一个程序集中。不管怎样,你能举一个导入的例子吗?谢谢啊,我读错了,所以您在不同于vm的程序集中有视图,您需要为viewlocator提供逻辑来搜索额外的名称空间,因为默认情况下它不知道如何在那里查看。我会更新我的答案,当我说CM时,我是指Caliburn Micro:)好的,但我刚从CM开始,所以你能详细解释我吗?我真的不知道关于它的任何事情更新了我的答案-我建议先读一读,实际上,熟悉简单的东西不应该超过几个小时,而熟悉restlink则不应该超过几天。域名已过期:(我修复了链接,请参见
namespace Caliburn.Micro.Test
{
    public class AppBootstrapper : BootstrapperBase
    {
        SimpleContainer container;

        public AppBootstrapper()
        {
            this.Start();
        }

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

            this.container.Singleton<IWindowManager, WindowManager>();
            this.container.Singleton<IEventAggregator, EventAggregator>();
            this.container.PerRequest<IShell, ShellViewModel>();
        }

        protected override object GetInstance(Type service, string key)
        {
            var instance = this.container.GetInstance(service, key);
            if (instance != null)
                return instance;

            throw new InvalidOperationException("Could not locate any instances.");
        }

        protected override IEnumerable<object> GetAllInstances(Type service)
        {
            return this.container.GetAllInstances(service);
        }

        protected override void BuildUp(object instance)
        {
            this.container.BuildUp(instance);
        }

        protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
        {
            this.DisplayRootViewFor<IShell>();
        }

        protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
        {

            var assemblies = new List<Assembly>()
            {
                Assembly.GetExecutingAssembly(),
                Assembly.Load("Caliburn.Micro.Test.ViewModel"),
            };

            return assemblies;
        }
    }
}
namespace Caliburn.Micro.Test.ViewModel
{
    public interface IShell
    {
    }

    public class ShellViewModel : IShell
    {
    }
}
protected override IEnumerable<Assembly> SelectAssemblies()
{
    return new[] {
        Assembly.GetExecutingAssembly()
    };
}