Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find view for ViewModel

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

using System.ComponentModel.Composition;

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

Because of some reason, I get the following message on the tab control:

Cannot find view for ReferenceMaintenanceWorkspace.MyViewModel.

Could you please explain why this could happen? Thanks.

like image 437
David Shochet Avatar asked Jun 18 '12 12:06

David Shochet


2 Answers

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

like image 118
pmezykowski Avatar answered Sep 18 '22 22:09

pmezykowski


I argee,I think fix this from two way. 1.In solution you should have two folders , one name is "Views" another is "ViewModels".

2.In your bootstrapper you need to add the assembly where the viewmodel or view is located:

protected override IEnumerable<Assembly> SelectAssemblies()
{
    var assemblies = base.SelectAssemblies().ToList();
    assemblies.Add(typeof(Project.ViewsNamespace.SomeView).Assembly);
   return assemblies;
}
like image 38
leelds Avatar answered Sep 22 '22 22:09

leelds