zoukankan      html  css  js  c++  java
  • Caliburn.Micro

    简介:Caliburn.Micro是Caliburn的一个轻量级版本开源架构,可以用于wpf,sliverlight,wp7等,和注重模块化的Prism比起来也有许多优点,具体比较可以参考

    此文 https://idanreuven.wordpress.com/2016/01/08/prism-vs-caliburn-micro/,本人用过Prism,所以想学习下这个架构,看看是否更方便开发。

    它的功能介绍参考官方文档吧,我也少废话,直接以实例开始入门吧。

    首先新建一个Wpf工程CaliburnTest,Targe framework 至少要选4.5版本

    1、使用nuget 安装Caliburn.Micro类库

    2、删除MainWindow.xaml 并且删除App.xaml的  StartupUri="MainWindow.xaml"

    3、新建一个ViewModel类,命名为ShellViewModel 

    public class ShellViewModel 
    {
    
    }

    3、新建一个Bootstrapper类,继承BootstrapperBase

    public class Bootstrapper: BootstrapperBase {
    public Bootstrapper()
    {
    Initialize(); 
    }
    
    protected override void OnStartup(object sender, StartupEventArgs e) {
    DisplayRootViewFor<ShellViewModel>();
    }
    }

    重写OnStartup方法,使用 DisplayRootViewFor<ShellViewModel>();指定启动的ViewModel,Caliburn.Micro可以根据xxxxViewModel对应xxxxView的协定,自动实例化View,Caliburn.Micro支持View First和ViewModel First两种方式来创建View。完全不用在View的后台代码中写DataContext=new xxxViewModel()代码,十分方便。

    4、创建视图 ShellView,注意要按照上述的协定来命名

    <Window x:Class="CaliburnTest.ShellView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShellView" >
    <Grid>
    <TextBlock>dddd</TextBlock>
    </Grid>
    </Window>

    5 修改App.xaml ,加入如下红色代码,注意wpf中和sliverlight中,此处的写法是有区别的,官网给出的是sliverlight的写法

    <Application x:Class="CaliburnTest.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:CaliburnTest">
    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
    <local:Bootstrapper x:Key="bootstrapper" />
    </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>
    </Application>

    运行测试就可以看到窗体启动了。这篇就到此为止,只讲讲如何搭建框架,下一篇再学习binding,Action的协定

  • 相关阅读:
    [HAOI 2007]上升序列
    转载:分布式与集群的区别究竟是什么?
    转载:5个顶级异步Python框架 https://geekflare.com/?s=python
    代码走读 airflow
    走读中学到的技巧 airflow
    sqlalchemy 相关
    pandas 筛选
    pandas IO
    服务端高并发分布式架构演进之路 转载,原文地址:https://segmentfault.com/a/1190000018626163
    pandas 6 时间
  • 原文地址:https://www.cnblogs.com/karl-F/p/6563817.html
Copyright © 2011-2022 走看看