出于某种原因,我收到Cannot find view for CaliburnPractice.ViewModel
错误。我已经在这里查看了一些答案,但没有一个对我有用。我已将视图和视图模型放入单独的命名文件夹中,并且我已经覆盖了SelectedAssembly方法。到底是怎么回事?请参阅下面的代码。
ViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
namespace CaliburnPractice
{
public class ViewModel : PropertyChangedBase
{
}
}
的App.xaml
<Application x:Class="CaliburnPractice.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CaliburnPractice"
>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:Bootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
PracticeView.xaml
<UserControl x:Class="CaliburnPractice.PracticeView"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Width="300" Height="300" Background="LightBlue">
</Grid>
Bootstrapper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using System.Reflection;
namespace CaliburnPractice
{
public class Bootstrapper : BootstrapperBase
{
public Bootstrapper()
{
Initialize();
}
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
base.OnStartup(sender, e);
DisplayRootViewFor<ViewModel>();
}
protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
{
return new[]
{
Assembly.GetExecutingAssembly()
};
}
}
}
答案 0 :(得分:3)
因为它正在查找View,您的viewmodel被命名为ViewModel ...您列出的视图是PracticeView ...
ShellView - &gt; ShellViewModel
MainView - &gt; MainViewModel等......
因此,练习视图 - &gt; PracticeViewModel会得到解决....
SelectedAssembly用于不同DLL中的单独视图/视图模型
除非你不包括我们可能需要知道的任何内容......