MVVMLight leaning note
Learning Note For MvvmLight
MvvmLight quitstart
refer link1 : MVVMLight HelloWorld
mc:Ignorable usage.
we have a lot of places using mc:Ignorable
in our xaml. it is used to Comment code in xaml.how to use it in our xaml, we can refer this topic.
SimpleIOC
ViewModelLocator.cs Analysis
when we use mvvmlight template, we will have a file called ViewModelLocator.cs General Structor here:
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;namespace mvvmtemplate.ViewModel
{
///
/// This class contains static references to all the view models in the
/// application and provides an entry point for the bindings.
///public class ViewModelLocator
{
///
/// Initializes a new instance of the ViewModelLocator class.
///public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);////if (ViewModelBase.IsInDesignModeStatic)
////{
//// // Create design time view services and models
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
////}
////else
////{
//// // Create run time view services and models
//// SimpleIoc.Default.Register<IDataService, DataService>();
////} SimpleIoc.Default.Register<MainViewModel>();
} public MainViewModel Main
{
get
{
return ServiceLocator.Current.GetInstance<MainViewModel>();
}
} public static void Cleanup()
{
// TODO Clear the ViewModels
}
}
}
three key point: ServiceLocator.SetLocatorProvider(()=>SimpleIoc.Default) SimpleIoc.Default.Register() ServiceLocator.Current.GetInstance()
for usage of SimpleIoc.Default.Register<>(), we can see the dll of the MvvmLight, a lot of overload functions about this. It is used to register the class to the SimpleIoc. Note: T class should only have one Contructor function, otherwise, it will report a error.
ServiceLocator.Current.GetInstance(), it is used to get a instance of the Class T. it is used to for singleInstance mode, other overload functions definited in dll.
Messager
it is used to send specified message between MVVM. Simple usage.
Register a specified message to an object.
Sample code:Messenger.Default.Register(object, Action);
Summary:
Registers a recipient for a type of message TMessage. The action parameter will be executed when a corresponding message is sent.
Registering a recipient does not create a hard reference to it, so if this recipient is deleted, no memory leak is caused.
Send a specified message.
Sample code:public virtual void Send(TMessage message){}
Summary:
Sends a message to registered recipients. The message will reach all recipients that registered for this message type using one of the Register methods.
Type Parameters:
TMessage: The type of message that will be sent.
Parameters:
message: The message to send to registered recipients.
How to use:
Messenger.Default.Send(new TMessage(s));
MVVMLight leaning note的更多相关文章
- UWP开发之Mvvmlight实践九:基于MVVM的项目架构分享
在前几章介绍了不少MVVM以及Mvvmlight实例,那实际企业开发中将以那种架构开发比较好?怎样分层开发才能节省成本? 本文特别分享实际企业项目开发中使用过的项目架构,欢迎参照使用!有不好的地方欢迎 ...
- UWP开发之Mvvmlight实践八:为什么事件注销处理要写在OnNavigatingFrom中
前一段开发UWP应用的时候因为系统返回按钮事件(SystemNavigationManager.GetForCurrentView().BackRequested)浪费了不少时间.现象就是在手机版的详 ...
- UWP开发之Mvvmlight实践七:如何查找设备(Mobile模拟器、实体手机、PC)中应用的Log等文件
在开发中或者后期测试乃至最后交付使用的时候,如果应用出问题了我们一般的做法就是查看Log文件.上章也提到了查看Log文件,这章重点讲解下如何查看Log文件?如何找到我们需要的Packages安装包目录 ...
- 三星Note 7停产,原来是吃了流程的亏
三星Note 7发售两个月即成为全球噩梦,从首炸到传言停产仅仅47天.所谓"屋漏偏逢连天雨",相比华为.小米等品牌对其全球市场的挤压.侵蚀,Galaxy Note 7爆炸事件这场连 ...
- 《Note --- Unreal --- MemPro (CONTINUE... ...)》
Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...
- 《Note --- Unreal 4 --- Sample analyze --- StrategyGame(continue...)》
---------------------------------------------------------------------------------------------------- ...
- [LeetCode] Ransom Note 赎金条
Given an arbitrary ransom note string and another string containing letters from all th ...
- [原创]MvvmLight中用IDialogService替代DialogMessage的用法
在新版的MvvmLight中,DialogMessage被标注为已过时,需要用IDialogService来替代,IDialogService的具体用法如下: 先在主窗体中实现IDialogServi ...
- Beginning Scala study note(9) Scala and Java Interoperability
1. Translating Java Classes to Scala Classes Example 1: # a class declaration in Java public class B ...
随机推荐
- 【.NET】单例模式标准写法
public sealed class Singleton { private static Singleton instance = null; static readonly object pad ...
- Solaris引导和关闭
OpenBoot PROM简称OBP,相当于PC的BIOS,是控制SUN服务器的引导过程.初始化配置某些硬件并提供某些诊断的工具.常见OBP命令 boot boot:从默认设备启动boot -s:从默 ...
- css3干货
CSS3是CSS2的升级版本,3只是版本号,它在CSS2.1的基础上增加了很多强大的新功能. 目前主流浏览器chrome.safari.firefox.opera.甚至360都已经支持了CSS3大部分 ...
- 网页热力图 heatmap js
HBuilder +js 实现网页热力图 废话不多说,上代码 <!DOCTYPE html> <html> <head> <title>111</ ...
- MongoDB的主要特性概述
一.文档数据模型 文档是一组属性名和属性的集合.相较于关系数据库复杂的规范化,面向文档的数据模型很容易以聚合的形式来表示数据.文档采用无Schema的形式,这种做法带来了一定的优势:首先,由应用程序, ...
- 7-ZIP实现数据高度压缩
From:http://www.cnblogs.com/killerlegend/p/3746395.html Author:KillerLegend Date:2013.5.22 选中文件,鼠标右键 ...
- delphi 基础之三 编写和调用dll文件
delphi 编写和调用dll文件 Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...
- Vmware下Ubuntu无法上网的问题
本来这个挺简单的个问题,但是由于很久没有使用虚拟机并且期间实体机网络环境发生了一些变化,导致了一些麻烦. 一般用NAT就行了,就是Vmware右下角那个图标(左起第4个)设置就行. 我这么设置了还是不 ...
- EF经验分享_jimmyzzc
刚刚接触EF,总结了一些在实际工作中的心德经验,与大家分享一下. 一.Excression表达式树 表达式目录树在LINQ中用于表示分配给类型为Expression<TDelegate>的 ...
- 小课堂week14 Google软件测试之道
读<Google软件测试之道> 在IT领域,Google是一面旗帜,是一家非常善于思考善于尝试的公司.随着面临挑战的不断增大,传统的测试开展方式也越来越力不从心,这本书讲述的就是一次完整的 ...