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 ...
随机推荐
- 设置lable文本内容的行间距
NSMutableParagraphStyle *paragraphStyle =[ [NSMutableParagraphStyle alloc] init]; paragraphStyle.lin ...
- 【MySQL】SQL语句嵌套1
mysql中You can't specify target table <tbl> for update in FROM clause错误的意思是说,不能先select出同一表中的某些值 ...
- C# 委托:把方法组合到一个数组中使用
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- Android IOS WebRTC 音视频开发总结(二一)-- 黑屏问题
本文主要介绍音视频通话中收到第一帧图像后视频一直卡住的问题,文章来自博客园RTC.Blacker,转载请说明出处. 因为苹果AppStore要求从2015年2月1日开始所有所有上架App必须支持arm ...
- C# 类型转换 Dictionary转Model类
/// <summary> /// 把Model转换为DataRow /// </summary> /// <typeparam name="T"&g ...
- DirectDraw打造极速图形引擎(Alpha混合)
显然DirectDraw是Windows下写2D图形程序的最好选择,虽然Direct3D也可以写,但是没DirectDraw简单方便,特别对于初学者,一来就接触那么多函数和参数总不是件愉快的事,所以我 ...
- Python开发的3种命令执行方法
在python开发中,我们常常需要执行命令,修改相关信息.那对于初学者来说,python中如何执行命令呢?今天,小编就为大家分享3种python命令执行的方法. 1. 使用os.system(&quo ...
- Cadence仿真利器,Cadence SI / PI Analysis – Sigrity安装及破解指南
Sigrity提供了丰富的千兆比特信号与电源网络分析技术,包括面向系统.印刷电路板(PCB)和IC封装设计的独特的考虑电源影响的信号完整性分析功能. Sigrity分析技术与Cadence Alleg ...
- 请注意designer中的NAME field
If you are trying to set the value of a field through PeopleCode and that field happens to be NAME t ...
- Winform开发常用控件之Checkbox和CheckedListBox
Winform的开发基本都是基于控件事件的,也就是事件驱动型的. 多选框的放置和值的获取有很多种,这里介绍几个简单常用的方法 1.直接放置Checkbox,并获取Checkbox的值 上图 做法也非常 ...