使用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. svn不支持中文路径问题的解决

    作者:朱金灿 来源:http://blog.csdn.net/clever101 svn的授权文件authz默认是不支持中文路径的,因此在精确控制中文文件夹的授权时往往会出错.要解决这个问题,需要用U ...

  2. reflect(反射)了解一点点

    A a = new A() 这个代码在程序编译阶段,会自己主动定位到A类上,而且新建一个A的实例. 可是假设我们希望程序在执行时.动态的创建一个A的实例.此时程序仅仅知道要从名字叫A的类中创建一个实例 ...

  3. storm 经常使用类

    弄 <dependency> <groupId>org.apache.storm</groupId> <artifactId>storm-core< ...

  4. 不要放弃使用border-box

    不知道有多少老前端像我这样,在项目中很少使用box-sizing这个属性值.因为CSS2.1中只有content-box这一种盒子模式,在CSS3还没有流行的时候,大家在工作中大量基于这种盒子模式写C ...

  5. 基于RDP瘦客户机协议的简要说明

    **************************************************************************************************** ...

  6. 辨异 —— 行星 vs 恒星

    star:恒星,planet:行星: 1. 恒星 恒星是指宇宙中靠核聚变产生的能量而自身能发热发光的星体(比如太阳).过去天文学家以为恒星的位置是永恒不变的,以此为名.但事实上,恒星也会按照一定的轨迹 ...

  7. React中的state与props的再理解

    props可以看做是 property 的缩写的复数,可以翻译为属性,类似于HTML 标签的自定义属性.在大多数React教程里讲 state 和 props 主要的区别在于 props 是不可变的, ...

  8. 下面介绍一个 yii2.0 的 Rbac 权限设置,闲话少说,直接上代码,

    1.首先我们要在组件里面配置一下 Rbac ,如下所示(common/config/main-local.php或者main.php).  'authManager' => [  'class' ...

  9. Spring boot+RabbitMQ环境

    Spring boot+RabbitMQ环境 消息队列在目前分布式系统下具备非常重要的地位,如下的场景是比较适合消息队列的: 跨系统的调用,异步性质的调用最佳. 高并发问题,利用队列串行特点. 订阅模 ...

  10. RadioButton分组的实现

    原文:RadioButton分组的实现     XAML如下 <StackPanel> <RadioButton GroupName="colorgrp"> ...