找不到ViewModel的视图

Dav*_*het 9 wpf caliburn.micro

我有一个使用Caliburn.Micro的wpf应用程序.我有一个视图MyView:

<UserControl x:Class="ReferenceMaintenanceWorkspace.MyView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         >
  <UserControl.Resources>
 </UserControl.Resources>
 <TabControl x:Name="Items" > 
</TabControl>
Run Code Online (Sandbox Code Playgroud)

我还有MyViewModel:

using System.ComponentModel.Composition;

namespace ReferenceMaintenanceWorkspace
{
[Export(typeof(MyViewModel))]
public class MyViewModel
{
  public MyViewModel()
  {
      base.DisplayName = "Reference Maintenance";
  }
Run Code Online (Sandbox Code Playgroud)

由于某种原因,我在选项卡控件上收到以下消息:

找不到ReferenceMaintenanceWorkspace.MyViewModel的视图.

你能解释一下为什么会发生这种情况吗?谢谢.

小智 13

仅仅是为了将来,它也会在重命名类/包之后发生,但在视图中,xaml文件"x:Class"不会更新.


Sha*_*rey 12

Caliburn Micro期待您项目中的某些文件结构.您的视图和视图模型应位于名为Views和ViewModels的单独文件夹中.

是一个很好的Hello World示例,描述了这一点.


小智 5

您应该在引导程序中覆盖SelectAssemblies,并在视图所在的位置提供程序集名称.