1. Caliburn是什么?
Caliburn是Rob Eisenberg在2009年1月26日(Rob's MIX10 talk "Build Your Own MVVM Framework")提出的一個MVVM類的開源框架,它是一套用于協助開發WPF,Silverlight,WP7和Win RT等的應用程式的庫,
Caliburn.Micro由Rob Eisenberg于2010年6月7日正式發布,
Caliburn.Micro是一個小而強大的框架,專為在所有XAML平臺上構建應用程式而設計,憑借對MVVM和其他經證明的UI模式的強大支持,Caliburn.Micro將使你能夠快速構建Solution,而無需犧牲代碼質量和可測驗性
2. 專案創建:
step1:創建工程,使用NuGet包管理工具為當前專案安裝Caliburn.Micro

step2:專案創建:
新建StartView.xaml
洗掉專案根目錄下的MainWindow.xaml
修改 App.xaml 洗掉StartupUri="MainWindow.xmal",
<Window x:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp8"
mc:Ignorable="d"
Title="StartView" Height="450" >
<Grid Background="Gray">
<Button x:Name="testBtn" Content="testBtn" HorizontalAlignment="Center" VerticalAlignment="Center" Height=" 50" Background="LightCyan"/>
</Grid>
</Window>
新建StartViewModel.cs
using Caliburn.Micro;
using System.Windows;
namespace WpfApp8
{
class StartViewModel : Screen
{
public StartViewModel()
{
}
public void testBtn()
{
MessageBox.Show("hello world!");
}
}
}
新建一個類繼承BootstrapperBase,這里我命名為MyBootstrapper
using Caliburn.Micro;
using System.Windows;
namespace WpfApp8
{
class MyBootstrapper : BootstrapperBase
{
public MyBootstrapper()
{
Initialize();//初始化框架
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<StartViewModel>();//顯示界面
}
}
}
運行結果:

代碼下載鏈接:
鏈接:https://pan.baidu.com/s/1tZlvSWOxxSZDIA1gMuITsQ
提取碼:添加小編微信zls20210502獲取!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/335028.html
標籤:.NET技术
上一篇:十六年編程基礎上形成一個低代碼開發平臺,歡迎大家吐槽
下一篇:走進WPF之UI布局
