使用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的匹配规则的更多相关文章

  1. Caliburn.Micro - 框架搭建

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

  2. Caliburn.Micro学习笔记(一)----引导类和命名匹配规则

    Caliburn.Micro学习笔记目录 用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeplex.com/ 文档也写的很详 ...

  3. Caliburn.Micro学习笔记(二)----Actions

    Caliburn.Micro学习笔记目录 上一篇已经简单说了一下引导类和简单的控件绑定 我的上一个例子里的button自动匹配到ViewModel事件你一定感觉很好玩吧 今天说一下它的Actions, ...

  4. AvalonDock 2.0+Caliburn.Micro+MahApps.Metro实现Metro风格插件式系统(一)

    随着IOS7由之前UI的拟物化设计变为如今的扁平化设计,也许扁平化的时代要来了,当然我们是不是该吐槽一下,苹果什么时候也开始跟风了,自GOOGLE和微软界面扁平化过后,苹果也加入了这一队伍. Aval ...

  5. Caliburn.Micro 杰的入门教程1(翻译)

    Caliburn.Micro 杰的入门教程1(原创翻译)Caliburn.Micro 杰的入门教程2 ,了解Data Binding 和 Events(翻译)Caliburn.Micro 杰的入门教程 ...

  6. 使用Caliburn.Micro系列2:Convention

    CM中实现一个比较有意思的特性,就是智能匹配. 通常使用MVVM的写法:在匹配 View和ViewModel时会使用DataContext,在匹配数据属性时使用Binding,在匹配事件命令时使用Co ...

  7. 开源框架Caliburn.Micro

    Caliburn.Micro学习笔记----引导类和命名匹配规则   用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeple ...

  8. Caliburn.Micro(MVVM框架)

    一.首启窗体设置 1. 创建一个新的WPF应用程序并添加NuGet包:Caliburn.Micro 2. 删除项目自带的主窗口文件MainWindow.xaml 3. 在App.xaml项目文件中,删 ...

  9. 【整理总结】代码沉淀 - Caliburn.Micro - MV*模式短小精悍的框架

    Caliburn.Micro - Xaml made easy. web: https://github.com/Caliburn-Micro/Caliburn.Microdocument: http ...

随机推荐

  1. git基本原理

    git基本原理 一.总结 一句话总结:把原理那张图图背下来 1.git中的四大区,除了远程仓库和本地仓库,剩下两个是什么? 解答:工作区和暂存区. 2.git中的四大区(例如远程仓库和本地仓库),他们 ...

  2. SignalR+NAudio实现语音会话[WPF]

    原文:SignalR+NAudio实现语音会话[WPF] 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/lordwish/article/detai ...

  3. javaScript判断输入框是否为空

    其中获得和失去焦点的时候都判断了一次 <script> function fun01(f,s){//有参函数 参数不需要参数类型!! try{ var v = document.getEl ...

  4. 【63.63%】【codeforces 724A】Checking the Calendar

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 定制Octopress

    在 github pages 上搭建好 octopress 博客之后,博客的基本功能就能使用了.如果想自己定制也是没问题的,octopress 有较详尽的官方文档,原则上有问题求助官方即可:octop ...

  6. vs2008 命令窗口 命令窗口 和 反汇编窗口的使用

    visual studio 的功能相当强大,用了一年多,也只是了解了皮毛.今天学习了一下VS2008 的 即时窗口 命令窗口 和 反汇编窗口的使用.之所以会想到要使用即时窗口是因为最近开发遇到了一个问 ...

  7. 机器学习: Viola-Jones 人脸检测算法解析(一)

    在计算机视觉领域中,人脸检测或者物体检测一直是一个非常受关注的领域,而在人脸检测中,Viola-Jones人脸检测算法可以说是非常经典的一个算法,所有从事人脸检测研究的人,都会熟悉了解这个算法,Vio ...

  8. 监听WPF依赖属性

    原文:监听WPF依赖属性 当我们使用依赖属性的时候,有时需要监听它的变化,这在写自定义控件的时候十分有用, 下面介绍一种简单的方法.   如下使用DependencyPropertyDescripto ...

  9. Efficient store queue architecture

    One embodiment of the present invention provides a store queue that applies the stores to a memory s ...

  10. python3 小技巧(2)

    原文 http://blog.csdn.net/jclass/article/details/6145078 一. base64 编码和解码任意的二进制字符串到文本字符串(主要用在HTTP EMAIL ...