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. Spring与Quartz的整合实现定时任务调度

    摘自: http://kevin19900306.iteye.com/blog/1397744 最近在研究Spring中的定时任务功能,最好的办法当然是使用Quartz来实现.对于一个新手来说,花了我 ...

  2. Android IOS WebRTC 音视频开发总结(二八)-- 多人视频方案介绍

    很多人问视频会议,在线教学,主播怎么弄,所以整理下这方面的开源解决方案, 同时为了方便测试,在自己服务器上搭建了相应的服务端,文章来自博客园RTC.Blacker,转载请说明出处. 简单来说,WEBR ...

  3. Linux系统快速启动方案

    =========================        基本常识       ========================= Linux系统基本启动流程: 1. CPU从ROM(如果有的 ...

  4. 著名的二分查找的BUG

    int binarySearch(int a[], int key, int length) { int low = 0; int high = length - 1; while (low < ...

  5. Windows Phone 显示长文本

    文采不好,将就着看,见谅 思路最重要,故本文不提供源码下载 参考项目: http://www.windowsphone.com/zh-cn/store/app/%E5%BF%83%E7%90%86fm ...

  6. [原]hdu2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (这个只是题目名字) (多重背包)

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.hdu.edu.cn/showproblem.php?pid=2191 题意:多重背包问题.转换成为01 ...

  7. MySQL深入利用Ameoba实现读写分离

    3 ameoba安装配置   3.1 安装配置JDK [root@stu15 ~]# rpm -ivh jdk-7u67-linux-x64.rpm [root@stu15 ~]# cd /usr/j ...

  8. read 不回显的方法

    方法就是: stty -echo #设置输入字符不回显 #此处用read语句接收用户输入的内容 stty echo #取消不回显状态 stty erase '^H'

  9. 请注意designer中的NAME field

    If you are trying to set the value of a field through PeopleCode and that field happens to be NAME t ...

  10. Silverlight动态设置WCF服务Endpoint

    2013-02-02 05:57 by jv9, 1763 阅读, 3 评论, 收藏, 编辑 去年12月收到一位朋友的邮件,咨询Silverlight使用WCF服务,应用部署后一直无法访问的问题,通过 ...