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. 創建HTTP 服務器

    var http = require('http'); var fs = require('fs'); var server = http.createServer(function(req, res ...

  2. Android IOS WebRTC 音视频开发总结(六五)-- 给韩国电信巨头做咨询

    本文主要总结咨询过程中的一些问题,文章最早发表在我们的微信公众号上,详见这里,欢迎关注微信公众号blackerteam 韩国电信巨头sk想了解国内移动互联网rtc现状,所以上周请我过去给他们的相关人员 ...

  3. Html.ActionLink

    一 Html.ActionLink("linkText","actionName") 该重载的第一个参数是该链接要显示的文字,第二个参数是对应的控制器的方法, ...

  4. 信息图形(Infographic)

    信息图形(Infographic),又称为信息图,是指数据.信息或知识的可视化表现形式.信息图形主要应用于必须要有一个清楚准确的解释或表达甚为复杂且大量的信息,例如在各式各样的文件档案上.各个地图及标 ...

  5. Linux命令行选项及参数

    1.main函数参数形式 int main(int argc , char *argv[] , char *env[]); //第一个参数argc代表命令行的参数个数 //第二个参数依次指向各个参数, ...

  6. c#桌面小软件

    这是以前练习时用c#做的桌面小软件,今天回顾下. 这是设计界面 可以看出该程序能够播放网络歌曲及浏览新闻. 实现:歌曲来源百度API,播放WindowsMediaPlayer api地址:string ...

  7. Custom PeopleSoft Queries

      The following SQL identifies custom queries created in your system from the PSQRYDEFN PeopleTools ...

  8. winform 打包部署

    1.使用VS 自带的打包工具,制作winform安装项目 开发环境:VS 2008 Access 操作系统:Windows XP 开发语言:C# 步骤: 第一步:打开开发环境VS2008,新建项目,选 ...

  9. 《第一行代码--Android》阅读笔记之广播

    广播接收器 1.注册方式 动态注册:在程序中注册,如在Activity里的onCreate()方法中注册 静态注册:在AndroidManifest.xml中注册   2.可接收哪些广播 接收系统消息 ...

  10. kettle的windows安装

    1.首先去官网下载安装包,这个安装包在所有平台上是通用的. 2.kettle是java语言开发的,所以需要配置JAVA_HOME 3.解压kettle的安装包 4.配置环境变量,KETTLE_HOME ...