1
出於某種原因,我得到Cannot find view for CaliburnPractice.ViewModel
錯誤。我已經看過這裏的一些答案,但沒有人爲我工作。我已經把視圖和viewmodel放到單獨的命名文件夾中,我已經重寫了SelectedAssembly方法。到底是怎麼回事?看到我的代碼如下。儘管SelectedAssembly被重寫,但找不到ViewModel的視圖
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()
};
}
}
}
這是非常重要的。我把所有的觀點/視角模型都設置得很完美。但是因爲我的視圖模型與視圖名稱略有不同(比如添加一個單詞),Caliburn無法找到它。這解決了我的問題! – AliEgseem