添加引用
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>

本文介绍如何使用 Caliburn.Micro 框架搭建 WPF 应用程序的基本结构,包括添加必要的 DLL 引用、创建 ViewModel 和 View,并配置 Bootstrapper 启动程序。

被折叠的 条评论
为什么被折叠?



