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

  1. 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()

  1. 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.

  2. 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.

  1. 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.

  1. 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的更多相关文章

  1. UWP开发之Mvvmlight实践九:基于MVVM的项目架构分享

    在前几章介绍了不少MVVM以及Mvvmlight实例,那实际企业开发中将以那种架构开发比较好?怎样分层开发才能节省成本? 本文特别分享实际企业项目开发中使用过的项目架构,欢迎参照使用!有不好的地方欢迎 ...

  2. UWP开发之Mvvmlight实践八:为什么事件注销处理要写在OnNavigatingFrom中

    前一段开发UWP应用的时候因为系统返回按钮事件(SystemNavigationManager.GetForCurrentView().BackRequested)浪费了不少时间.现象就是在手机版的详 ...

  3. UWP开发之Mvvmlight实践七:如何查找设备(Mobile模拟器、实体手机、PC)中应用的Log等文件

    在开发中或者后期测试乃至最后交付使用的时候,如果应用出问题了我们一般的做法就是查看Log文件.上章也提到了查看Log文件,这章重点讲解下如何查看Log文件?如何找到我们需要的Packages安装包目录 ...

  4. 三星Note 7停产,原来是吃了流程的亏

    三星Note 7发售两个月即成为全球噩梦,从首炸到传言停产仅仅47天.所谓"屋漏偏逢连天雨",相比华为.小米等品牌对其全球市场的挤压.侵蚀,Galaxy Note 7爆炸事件这场连 ...

  5. 《Note --- Unreal --- MemPro (CONTINUE... ...)》

    Mem pro 是一个主要集成内存泄露检测的工具,其具有自身的源码和GUI,在GUI中利用"Launch" button进行加载自己待检测的application,目前支持的平台为 ...

  6. 《Note --- Unreal 4 --- Sample analyze --- StrategyGame(continue...)》

    ---------------------------------------------------------------------------------------------------- ...

  7. [LeetCode] Ransom Note 赎金条

    
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
th ...

  8. [原创]MvvmLight中用IDialogService替代DialogMessage的用法

    在新版的MvvmLight中,DialogMessage被标注为已过时,需要用IDialogService来替代,IDialogService的具体用法如下: 先在主窗体中实现IDialogServi ...

  9. 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 ...

随机推荐

  1. 完成《Java编程入门》初稿

    Java编程入门 现在的运维工程师不但要懂得集合网络.系统管理而且要和开发人员一起调试系统,社会上也需要"复合性"的运维人员,所以需要做运维的也要懂一些开发,知道软件系统接口的调试 ...

  2. UNICODE字符串与多字节字符串的转换

    相互转换的两个函数的声明: 1. 多字节字符串与宽字符串的转换 int MultiByteToWideChar( UINT CodePage, // code page,一般设为 CP_ACP DWO ...

  3. win7和win8如何设置快速启动栏

    a.在任务栏上右键 -> 工具栏 -> 新建工具栏 -> 跳出选择文件夹对话框,在文件夹里面(光标山洞处)输入这个路径,然后按回车: %userprofile%\AppData\Ro ...

  4. JAVA语法细节(1)

    1.变量的作用域 变量的作用域从变量定义的位置开始,到变量所在的那对大括号结束.变量定义内存开辟一块空间用于该变量,变量到达作用域时,该变量从内存中消失. 2.变量的数据类型 变量基本数据类型:byt ...

  5. POJ 1195

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 13774   Accepted: 6393 De ...

  6. 基本的Web控件二

    ListBox控件 ListBox控件用于创建多选的列表框,而可选项是通过ListItem元素来定义的. ListBox控件常用的属性: 1.Count:表示列表框中条目的总数. 2.Items:表示 ...

  7. ios英语口语800句应用源码

    前几天突发奇想做了个很水的应用,名字叫chinese 800(汉语口语800句),现在让别人传上去了(正在传). 今天又改了一下变成了英语口语800句.加了广告条 ui 没有优化,我随便整的两个图片, ...

  8. WP8.1 添加启动画面

    1.新建WP8.1工程,将需要设置为启动画面的图片添加到工程中,并且重命名为splash-Phone-sdk.png(必须命名为该名字). 2.在工程中有Package.appxmanifest,双击 ...

  9. vim编辑器编程配置

    打开/etc/vim/vimrc 添加命令: set cindent  "使用C样式的缩进 syntax on   "语法高亮 set tabstop=4 set softtabs ...

  10. 兼容主流浏览器的CSS透明代码

    透明往往能产生不错的网页视觉效果下面是兼容主流浏览器的CSS透明代码.transparent_class {  filter:alpha(opacity=50);  -moz-opacity:0.5; ...