Unable to find view for ViewModel

I have a wpf application using Caliburn.Micro. I have a view of 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> 

I also have a MyViewModel:

 using System.ComponentModel.Composition; namespace ReferenceMaintenanceWorkspace { [Export(typeof(MyViewModel))] public class MyViewModel { public MyViewModel() { base.DisplayName = "Reference Maintenance"; } 

For some reason, I get the following message in a tab control:

Unable to find view for ReferenceMaintenanceWorkspace.MyViewModel.

Could you explain why this could happen? Thanks.

+9
source share
4 answers

Caliburn Micro expects a specific file structure in your project. Your views and view models should be in separate folders named Views and ViewModels.

Here is a good Hello World example that describes this.

+12
source

Just for the future, this also happens after renaming classes / packages, but in mind that the xaml file "x: Class" is not updated.

+12
source

You must override SelectAssemblies in the bootstrapper and specify the name of the assembly in which your view is located.

+5
source

make sure you have ViewModels and Views folders. Also, make sure that the names of your classes and usercontrols / windows also comply with the following naming conventions:

  • = ViewModels
  • == YoloViewModel
  • = Views
  • == YoloView

If the views and view models are in a different assembly, try the following:

In your bootloader, you need to add the assembly in which the viewmodel / view is located:

 protected override IEnumerable<Assembly> SelectAssemblies() { var assemblies = base.SelectAssemblies().ToList(); assemblies.Add(typeof(MyProject.Foo.ViewModels.YoloViewModel).Assembly); return assemblies; } 
+3
source

All Articles