前言

因为vs2010没有集成mvvmlight 所以想要使用mvvmlight的relaycomman需要引用dll

需要测试某个功能的时候,不能进行快带的集成

引用mvvmlight dll

如果以前有其它版本的vs能过nuget安装过,则目录 是:

c:\users\administrator.xdmwiwrtm7kc37y\documents\visual studio 2013\Projects\WpfApplication2\packages\MvvmLightLibs.4.2.30.0\lib\net40

引用

GalaSoft.MvvmLight.WPF4.dll

如何实现

xaml中的代码如下:

放一个button ,指定Button的命令是TestN, 这里是随便写的,全符合命名规范

注意:Datacontext的指定 ,如果不指定 ,命令不会触发。这里不加新类,直接写在CS里面。

就是为了测试而测试

<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication2="clr-namespace:WpfApplication2"
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Command="{Binding TestN}" Width="100" Height="100" Content="wefwfwef"/>
</Grid> </Window>

注意:

如果没有以下这句,会报错

 DataContext="{Binding RelativeSource={RelativeSource Self}}"

cs后端的代码如下

  public partial class MainWindow : Window
{
private RelayCommand _testN; public MainWindow()
{
InitializeComponent();
//DataContext = this;
} public RelayCommand TestN
{
get { return _testN??(_testN=new RelayCommand(() =>
{
TestNMethod();
})); }
set { _testN = value; }
} private void TestNMethod()
{
throw new NotImplementedException();
}
}

注意:

如果xaml中没有指定 datacontxt,则要在构造 函数中指定datacontext是本类。

调用以后TestNMethod()方法会被触发。

最新文章

  1. [C#] C# 知识回顾 - 特性 Attribute
  2. 已解决:Strict Standards: Only variables should be passed by reference in
  3. iOS开发 贝塞尔曲线UIBezierPath
  4. Mac安装win7
  5. ORA-27101:shared memory realm does not exist的问题
  6. POJ 2001-Shortest Prefixes(Trie 入门)
  7. 退役笔记一#MySQL = lambda sql : sql + &amp;#39; Source Code 4 Explain Plan &amp;#39;
  8. tomcat root dir log 配置
  9. Sublime Text3中最常用的快捷键
  10. 射频识别技术漫谈(16)——Mifare UltraLight
  11. PHP判断一个变量是否可以通过foreach进行遍历
  12. struts2-剩余
  13. 使用RStudio调试(debug)基础学习(一)
  14. (实用)pip源
  15. tomcat监控脚本(监控进程,测试接口,告警动作为发送邮件)
  16. Postman无法正常启动解决办法
  17. sql两个日期之间的查询统计
  18. spring boot 基础篇 -- 自带图片服务器
  19. asp.net 网站监控方案
  20. PAT乙级1001

热门文章

  1. GC之五--SystemGC完全解读
  2. 学习笔记之数据库Database
  3. Unreal Engine 4 笔记 2
  4. Lua C++互传结构体实例
  5. 管理11gRAC基本命令 (转载)
  6. webpack(2)--Entry
  7. 支持向量机(理论+opencv实现)
  8. mysql各种连接总结
  9. svn完整搭建
  10. 解决 php 报错 open_basedir restriction in effect或者nginx提示No input file specified怎么办