Caliburn.Micro框架之Action Convertions
首先新建一个项目,名称叫Caliburn.Micro.ActionConvertions
然后删掉MainWindow.xaml
然后去app.xaml删掉StartupUri这行代码
其次,安装Caliburn.Micro,Caliburn.Micro.Core,这两个Nuget包,如下图
然后新建一个类Bootstrapper,这个类是引导作用,比如重写了首页的引导,ioc注入等
然后在项目中新建ViewModels,Views,在Views中添加窗口ShellView,在ViewModels中添加类ShellViewModel,如下图
public class Bootstrapper : BootstrapperBase
{
private SimpleContainer container; public Bootstrapper()
{
Initialize();
} protected override void Configure()
{
container = new SimpleContainer(); container.Singleton<IWindowManager, WindowManager>(); container.PerRequest<ShellViewModel>();
} protected override void OnStartup(object sender, StartupEventArgs e)
{
DisplayRootViewFor<ShellViewModel>();
} protected override object GetInstance(Type service, string key)
{
return container.GetInstance(service, key);
} protected override IEnumerable<object> GetAllInstances(Type service)
{
return container.GetAllInstances(service);
} protected override void BuildUp(object instance)
{
container.BuildUp(instance);
}
}
再继续新建一个类TaskHelper
TaskHelper类的内容入下
修改ShellViewModel类
public class ShellViewModel : Screen
{
private string output; public void Clear() => Output = String.Empty; public void SimpleSayHello() => Output = "Hello from Caliburn.Micro"; public void SayHello(string name) => Output = $"Hello {name}"; public bool CanSayHello(string name) => !String.IsNullOrEmpty(name); public Task SayGoodbyeAsync(string name)
{
Output = $"Goodbye {name}"; return TaskHelper.FromResult(true);
} public bool CanSayGoodbye(string name) => !String.IsNullOrEmpty(name); public string Output
{
get { return output; }
set { Set(ref output, value); }
}
}
然后修改ShellView页面的布局
<Window x:Class="Caliburn.Micro.ActionConvertions.Views.ShellView"
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:Caliburn.Micro.ActionConvertions.Views"
mc:Ignorable="d"
xmlns:cm="http://www.caliburnproject.org"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
Title="ShellView" Height="" Width="">
<Window.Resources>
<Style x:Key="ActionButtonStyle"
TargetType="Button">
<Setter Property="Margin"
Value="0,10,0,0" />
<Setter Property="HorizontalAlignment"
Value="Stretch" />
</Style>
</Window.Resources>
<Grid>
<ScrollViewer>
<StackPanel Margin="24,12">
<TextBlock>
<Run Text="Output:"
FontWeight="Bold" />
<Run Text="{Binding Output}" />
</TextBlock> <TextBlock Text="Name" />
<TextBox x:Name="Name"
Margin="0,10,0,0"
HorizontalAlignment="Stretch" /> <Button x:Name="Clear"
Content="Clear"
Style="{StaticResource ActionButtonStyle}" />
<Button x:Name="SimpleSayHello"
Content="Simple Say Hello"
Style="{StaticResource ActionButtonStyle}" />
<Button cm:Message.Attach="SimpleSayHello"
Content="Simple Say Hello (using Message.Attach)"
Style="{StaticResource ActionButtonStyle}" />
<Button cm:Message.Attach="[Event MouseDoubleClick] = [SimpleSayHello]"
Content="Simple Say Hello (Custom Event - Double Tapped)"
Style="{StaticResource ActionButtonStyle}" />
<Button x:Name="FullSyntax"
Content="Simple Say Hello (Full Behaviour Syntax)"
Style="{StaticResource ActionButtonStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cm:ActionMessage MethodName="SimpleSayHello" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<Button x:Name="SayHello"
Content="Say Hello (with parameter)"
Style="{StaticResource ActionButtonStyle}" />
<Button cm:Message.Attach="SayHello(Name)"
Content="Say Hello (with parameter and Message.Attach)"
Style="{StaticResource ActionButtonStyle}" />
<Button x:Name="SayGoodbye"
Content="Say Goodbye (async method)"
Style="{StaticResource ActionButtonStyle}" />
</StackPanel>
</ScrollViewer>
</Grid>
</Window>
修改App.xaml的引导程序代码
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary>
<local:Bootstrapper x:Key="Bootstrapper" />
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
然后运行如下图所示
如果转载请标明博客地址https://www.cnblogs.com/R00R/,谢谢
Caliburn.Micro框架之Action Convertions的更多相关文章
- Caliburn Micro框架
Caliburn Micro框架快速上手(WP) 一.使用nuget添加起始工程 二.修改App.xaml文件和App.xaml.cs文件 AppBootstrapper介绍: AppBootst ...
- Caliburn.Micro - 框架搭建
简介:Caliburn.Micro是Caliburn的一个轻量级版本开源架构,可以用于wpf,sliverlight,wp7等,和注重模块化的Prism比起来也有许多优点,具体比较可以参考 此文 ht ...
- Caliburn.Micro框架之Bindings
新建一个WPF项目,将其命名为Caliburn.Micro.BindingsDemo 其次安装Caliburn.Micro,安装Caliburn.Micro的同时也会安装Caliburn.Micro. ...
- Caliburn Micro框架快速上手(WP)
一.使用nuget添加起始工程 二.修改App.xaml文件和App.xaml.cs文件 AppBootstrapper介绍: AppBootstrapper根据中文的直译可以 ...
- WPF +MVVM(Caliburn.Micro)项目框架
最近做了一个软件,这个软件不是网站,但是与HTML,AJAX等技术密切相关,也不是只有单纯的数据库增删改查,还涉及到线程协调,比较复杂的文本处理…… 这样的软件,用OA,ERP的框架显然是不合适的,因 ...
- 从0到1:使用Caliburn.Micro(WPF和MVVM)开发简单的计算器
从0到1:使用Caliburn.Micro(WPF和MVVM)开发简单的计算器 之前时间一直在使用Caliburn.Micro这种应用了MVVM模式的WPF框架做开发,是时候总结一下了. Calibu ...
- [WPF] Caliburn Micro学习二 Infrastructure
Caliburn Micro学习一 Installation http://blog.csdn.net/alvachien/article/details/12985415 Step 1. 无论是通过 ...
- [Caliburn.Micro专题][1]快速入门
目录 1. 什么是Caliburn.Micro? 2. 我是否需要学习CM框架? 3. 如何下手? 3.1 需要理解以下几个概念: 3.2 工程概览 3.3 示例代码 开场白:本系列为个人学习记录,才 ...
- 开源框架Caliburn.Micro
Caliburn.Micro学习笔记----引导类和命名匹配规则 用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeple ...
随机推荐
- Dynamics CRM 快速获取custom entity
我们可以使用Command来实现快速获取custom entity的值. 创建cmd 并且在nuget中引用 CRMSDK 复制下面的代码. userName 为登陆CRM的email passwo ...
- 高阶函数及 map、reduce、filter 的实现
博客地址:https://ainyi.com/85 2020 开年国家经历了不少困难,最为凶猛的局势就是新型冠状病毒的蔓延,国务院最终决定春节假期延长至==2 月 2 号==:公司决定 3 - 7 号 ...
- window nginx 中文路径, 文件名乱码问题解决
window nginx 中文路径, 文件名乱码, error, not found 此问题是由于windows系统编码与nginx编码设置不一致导致的,因此我们要统一二者的编码 nginx编码设置 ...
- Web 项目没有发布到我们安装的tomcat目录下
新手做Web项目的时候,在Ecplise把app发布到tomcat,但最后项目并没有发布到我们自己安装的 tomcat目录下,而是在.metadata\.plugins\org.eclipse.wst ...
- Docker快速上手之搭建SpringBoot项目
Docker是基于Go语言实现的云开源项目. Docker的主要目标是“Build,Ship and Run Any App,Anywhere”,也就是通过对应用组件的封装.分发.部署.运行等生命周期 ...
- PyCharm2019.3.3专业版完美激活
在 PYPL 编程语言榜单上,Python 因近几年受欢迎程不断提高而继续霸榜.俗话说“萝卜青菜,各有所爱”,在众多的编辑器当中,因每个人的使用习惯不同,也会选择各自的喜欢的编辑器.Pycharm 分 ...
- python学习记录(二)
0824--https://www.cnblogs.com/fnng/archive/2013/02/24/2924283.html 如果需要写一个非常非常长的字符串,它需要跨多行,那么,可以使用三个 ...
- qt creator源码全方面分析(2-6)
目录 User Interface Text Guidelines 语法和风格 标点 编写工具提示tooltips 编写消息 UI文本大写 使用书本样式大写 使用句子样式大写 准备本地化 标记UI文本 ...
- Codeforces_712_B
http://codeforces.com/problemset/problem/712/B 水,判断奇偶即可. #include<iostream> #include<string ...
- LeetCode 218. The Skyline Problem 天际线问题(C++/Java)
题目: A city's skyline is the outer contour of the silhouette formed by all the buildings in that city ...