Caliburn.Micro 自定义View和ViewModel的匹配规则
使用TypeMappingConfiguration类
//Override the default subnamespaces
var config = new TypeMappingConfiguration
{
DefaultSubNamespaceForViewModels = "MyViewModels",
DefaultSubNamespaceForViews = "MyViews"
}; ViewLocator.ConfigureTypeMappings(config);
ViewModelLocator.ConfigureTypeMappings(config); //Resolves:
//MyProject.MyViewModels.CustomerViewModel -> MyProject.MyViews.CustomerView
//MyProject.MyViewModels.CustomerPageViewModel -> MyProject.MyViews.CustomerPage
//MyProject.MyViews.CustomerView -> MyProject.MyViewModels.CustomerViewModel
//MyProject.MyViews.CustomerPage -> MyProject.MyViewModels.CustomerPageViewModel //Change ViewModel naming convention to always exclude View suffix
var config = new TypeMappingConfiguration
{
DefaultSubNamespaceForViewModels = "MyViewModels",
DefaultSubNamespaceForViews = "MyViews",
IncludeViewSuffixInViewModelNames = false
}; ViewLocator.ConfigureTypeMappings(config);
ViewModelLocator.ConfigureTypeMappings(config); //Resolves:
//MyProject.MyViewModels.CustomerViewModel -> MyProject.MyViews.CustomerPage, MyProject.MyViews.CustomerView
//MyProject.MyViews.CustomerView -> MyProject.MyViewModels.CustomerViewModel
//MyProject.MyViews.CustomerPage -> MyProject.MyViewModels.CustomerViewModel //Change naming conventions to place name suffixes before the base name (i.e. name prefix)
var config = new TypeMappingConfiguration
{
NameFormat = "{1}{0}",
IncludeViewSuffixInViewModelNames = false
}; ViewLocator.ConfigureTypeMappings(config);
ViewModelLocator.ConfigureTypeMappings(config); //Resolves:
//MyProject.ViewModels.ViewModelCustomer -> MyProject.Views.PageCustomer, MyProject.Views.ViewCustomer
//MyProject.Views.ViewCustomer -> MyProject.ViewModels.ViewModelCustomer
//MyProject.Views.PageCustomer -> MyProject.ViewModels.ViewModelCustomer //Change naming conventions to omit name suffixes altogether (i.e. distinguish View and ViewModel types by namespace alone)
var config = new TypeMappingConfiguration
{
UseNameSuffixesInMappings = false
}; ViewLocator.ConfigureTypeMappings(config);
ViewModelLocator.ConfigureTypeMappings(config); //Resolves:
//MyProject.ViewModels.Customer -> MyProject.Views.Customer
//MyProject.Views.Customer -> MyProject.ViewModels.Customer //Configure for Spanish language and semantics
var config = new TypeMappingConfiguration()
{
DefaultSubNamespaceForViewModels = "ModelosDeVistas",
DefaultSubNamespaceForViews = "Vistas",
ViewModelSuffix = "ModeloDeVista",
ViewSuffixList = new List<string>(new string[] { "Vista", "Pagina" }),
NameFormat = "{1}{0}",
IncludeViewSuffixInViewModelNames = false
}; ViewLocator.ConfigureTypeMappings(config);
ViewModelLocator.ConfigureTypeMappings(config); //Resolves:
//MiProyecto.ModelosDeVistas.ModeloDeVistaCliente -> MiProyecto.Vistas.VistaCliente, MiProyecto.Vistas.PaginaCliente
//MiProyecto.Vistas.VistaCliente -> MiProyecto.ModelosDeVistas.ModeloDeVistaCliente
//MiProyecto.Vistas.PaginaCliente -> MiProyecto.ModelosDeVistas.ModeloDeVistaCliente
Caliburn.Micro 自定义View和ViewModel的匹配规则的更多相关文章
- Caliburn.Micro - 框架搭建
简介:Caliburn.Micro是Caliburn的一个轻量级版本开源架构,可以用于wpf,sliverlight,wp7等,和注重模块化的Prism比起来也有许多优点,具体比较可以参考 此文 ht ...
- Caliburn.Micro学习笔记(一)----引导类和命名匹配规则
Caliburn.Micro学习笔记目录 用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeplex.com/ 文档也写的很详 ...
- Caliburn.Micro学习笔记(二)----Actions
Caliburn.Micro学习笔记目录 上一篇已经简单说了一下引导类和简单的控件绑定 我的上一个例子里的button自动匹配到ViewModel事件你一定感觉很好玩吧 今天说一下它的Actions, ...
- AvalonDock 2.0+Caliburn.Micro+MahApps.Metro实现Metro风格插件式系统(一)
随着IOS7由之前UI的拟物化设计变为如今的扁平化设计,也许扁平化的时代要来了,当然我们是不是该吐槽一下,苹果什么时候也开始跟风了,自GOOGLE和微软界面扁平化过后,苹果也加入了这一队伍. Aval ...
- Caliburn.Micro 杰的入门教程1(翻译)
Caliburn.Micro 杰的入门教程1(原创翻译)Caliburn.Micro 杰的入门教程2 ,了解Data Binding 和 Events(翻译)Caliburn.Micro 杰的入门教程 ...
- 使用Caliburn.Micro系列2:Convention
CM中实现一个比较有意思的特性,就是智能匹配. 通常使用MVVM的写法:在匹配 View和ViewModel时会使用DataContext,在匹配数据属性时使用Binding,在匹配事件命令时使用Co ...
- 开源框架Caliburn.Micro
Caliburn.Micro学习笔记----引导类和命名匹配规则 用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeple ...
- Caliburn.Micro(MVVM框架)
一.首启窗体设置 1. 创建一个新的WPF应用程序并添加NuGet包:Caliburn.Micro 2. 删除项目自带的主窗口文件MainWindow.xaml 3. 在App.xaml项目文件中,删 ...
- 【整理总结】代码沉淀 - Caliburn.Micro - MV*模式短小精悍的框架
Caliburn.Micro - Xaml made easy. web: https://github.com/Caliburn-Micro/Caliburn.Microdocument: http ...
随机推荐
- require.js的用法详解
require.js的诞生是为了解决两大问题,第一实现js文件的异步加载,避免网页失去响应,第二管理模块之间的依赖性,便于代码的编写和维护. 一.为什么要用require.js? 最早的时候,所有Ja ...
- CF439E:The Untended Antiquity - 哈希 + 二维树状数组
Magic Door 题目大意 有一个n*m的网格,支持三中操作: 1.在x1,y1,x2,y2为顶点的矩形周围围上栅栏 2.将x1,y1,x2,y2为顶点的矩形周围的栅栏拆掉 3.询问x1,y1,x ...
- 【BZOJ 1022】 [SHOI2008]小约翰的游戏John
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1022 [题意] [题解] 和这题类似http://blog.csdn.net/harl ...
- 【t006】三角形分形描绘问题
Time Limit: 1 second Memory Limit: 50 MB [问题描述] 分形是以多种概念和方法相互冲击融合为特征的图形.分形所呈现的无穷玄机和美感引发人们去探索.分形使人们觉悟 ...
- Lua转让C功能
在上一篇文章中(C调用lua函数)中.讲述了怎样用c语言调用lua函数,通常,A语言能调用B语言,反过来也是成立的.正如Java 与c语言之间使用JNI来互调.Lua与C也能够互调. 当lua调用c函 ...
- base64编码转图片
protected void Button1_Click(object sender, EventArgs e) { //strImg为base64编码的图片字符串 string strImg = & ...
- 画廊视图(Gallery)的功能和用法
Gallery与Spinner组件有共同的父类:AbsSpinner,表明Gallery和Spinner都是一个列表框.它们之间的区别在于Spinner显示的是一个垂直的列表选择框吗,而Gallery ...
- node lesson3
var express = require('express'); var superagent = require('superagent'); var cheerio = require('che ...
- JavaScript取出字符串和尾随空格
书写JavaScript性能trim()之前和之后删除空字符串格,的功能的应用String物replace()方法去除空字符串端到端格.trim()例如,对于功能键下面的代码: <script ...
- WPF的页面导航
工作中之前接触过的WPF程序一直是使用TabControl作不同页面间的切换,每个Tab负责独立的功能,清晰简捷,所以一直就没有动力研究WPF自带的页面导航.(虽然接触过使用页面导航的WPF项目,也并 ...