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 ...
随机推荐
- 简化对象extend拓展
发现对对象继承或拷贝的时候,总是要$点来点去好麻烦,我的解决办法如下: (function(){ Object.prototype.extend = function(o){ $.extend(tru ...
- tty -s && mesg n
- 【MySQL】MySQL锁和隔离级别浅析二 之 INSERT
最近在整理线上性能时,发现一台线上DB出现两个insert产生的死锁问题 ------------------------ LATEST DETECTED DEADLOCK ------------- ...
- 让内层Div将外层Div撑开
在CSS排版中,如果一个层中的层使用了float浮动的话,那么就有可能会出现外层没有被内层撑开的情况,如以下代码所示: <div style="width:300px; "& ...
- hbase日常运维管用命令,region管理
1 Hbase日常运维 1.1 监控Hbase运行状况 1.1.1 操作系统 1.1.1.1 IO 群集网络IO,磁盘IO,HDFS IO IO越大说明文件读 ...
- Distant Supervision for relation extraction without labeled data
Distant Supervision for relation extraction without labeled data 远程监督:使用未标注语料做关系抽取 1. 背景: 关系抽取(某个人是否 ...
- 实现弹出收回菜单效果ios源码
REMenu能够提供下弹出来的菜单,跳转到不同的vc后菜单便会收起.菜单的弹收都有回弹(bounce)的效果.效果图: <ignore_js_op> 使用方法: 先把REMenu的文件夹复 ...
- Blend制作的下载动画
最近使用Blend制作了一个下载动画,感觉很有意思,所以这篇给各位介绍下如何使用Blend制作一个简单的下载动画的步骤 首先拖出一个圆,参数如下: 选中椭圆后单击Properties面板,选择“Fil ...
- 例题6-10 The Falling Leaves,UVA699
这道题我的思路是先通过递归构建树,然后进行遍历将位置和保存在map映射中,最后按顺序输出map集合中的值. 至于如何遍历,我是依次尝试了宽度优先遍历和深度优先遍历,当然这都是可以的.不过期间写错了很多 ...
- php中iconv函数使用方法
最近在做一个程序,需要用到iconv函数把抓取来过的utf-8编码的页面转成gb2312, 发现只有用iconv函数把抓取过来的数据一转码数据就会无缘无故的少一些. iconv函数库能够完成各种字符集 ...