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 ...
随机推荐
- C++中“强制转换”的四大天王
哈哈,这个标题有点搞笑了!笑一笑,十年少,希望大家都嗨心! 在C++中主要有四种强制类型转换:static_cast,reinterpret_cast,const_cast,dynamic_cast. ...
- extern c
extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...
- ASP.NET Razor 视图引擎编程参考
ASP.NET Razor 视图引擎编程参考 转载请注明出处:http://surfsky.cnblogs.com Rasor 视图引擎 http://msdn.microsoft.com/ ...
- JB for iOS 9.3
令人期待已久的JB再度现世,真是望穿秋水,千呼万唤始出来~ http://www.pangu.io/?flag=cn JB的过程顺利不卡关. 完成后就可以看到心爱的Cydia出现在桌面上了. 还需要A ...
- javaSE第七天
第七天 36 1. 成员变量和局部变量的区别(理解) 36 (1)在类中的位置不同 36 (2)在内存中的位置不同 36 (3)生命周期不同 36 (4)初始化值不同 ...
- 设备版本,设备号,APP版本,APP名称获取
//获取设备id号 UIDevice *device = [UIDevice currentDevice];//创建设备对象 NSString *deviceUID = [[NSString allo ...
- Java SE技术概览 - Jave SE Platform at a Glance
从学习到工作,使用Java有几年时间,一直没有好好端详一下她的“内涵”.无意中看到一个关于Java SE的概览图,发现Java中提供的API还挺系统全面,把她放到博客中,相信对于想系统了解Java技术 ...
- vim插件之SnipMate
SnipMate简介 snipMate一款功能强大的代码补齐插件,可自定义代码模板,并具备单词补齐的功能. vim插件snipMate下载地址 SnipMate安装 将snipMate.zip解压到~ ...
- IOS多线程(一)
一.绪论 1.进程:平时看到的一个应用程序,即可算作一个线程. 每个进程都有一个PID作为进程ID,有一个Process Name作为进程名字等. 2.线程:一个进程可以有多个线程,而每个线程只可属于 ...
- .NET程序员爱上网站[整理]
1.博客园(代码改变世界) http://www.cnblogs.com 2.开源中国社区(开源软件发现.使用和交流平台) http://www.oschina.net 3.CSDN(中国最大的IT社 ...