添加引用
Caliburn.Micro.dll
System.Windows.Interactivity.dll
Since Caliburn Micro is going to take care of creating the window for you, delete MainWindow.xaml and remove the StartupUri attribute from App.xaml.
<Application x:Class="CaliburnMicroApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
</Application.Resources>
</Application>
添加ViewModel 注意命名与View统一
using Caliburn.Micro;
namespace CaliburnMicroApp
{
public class AppViewModel : PropertyChangedBase
{
}
}
添加View(示例)
<UserControl x:Class="CaliburnMicroApp.AppView"
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">
<Grid Width="300" Height="300" Background="LightBlue">
</Grid>
</UserControl>
添加 Bootstrapper 程序启动项
using Caliburn.Micro;
namespace CaliburnMicroApp
{
public class AppBootstrapper : Bootstrapper<AppViewModel>
{
}
}
修改App.xaml
<Application x:Class="CaliburnMicroApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:CaliburnMicroApp"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:AppBootstrapper x:Key="bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>