示例代码

    public class RegisterUserViewModel
{
public UserInfo userInfo { get; set; } public ICommand ClickCommand { get; set; } public RegisterUserViewModel()
{
userInfo = new UserInfo();
userInfo.Age = ;
this.ClickCommand = new DelegateCommand<object>(OnClick, arg => true);
} void OnClick(object obj)
{
userInfo.Age += ;
}
}

ViewModel

<Window x:Class="mvvmTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid>
<Button Height="" HorizontalAlignment="Left" Margin="12,0,0,72" Name="btnClick" VerticalAlignment="Bottom" Width="" Command="{Binding ClickCommand}">Click me</Button>
<TextBlock Height="" Margin="12,44,0,0" Name="textBlock1" VerticalAlignment="Top" Text="UserName:" HorizontalAlignment="Left" Width="" />
<TextBlock Margin="12,93,0,0" Name="textBlock2" Height="" HorizontalAlignment="Left" VerticalAlignment="Top" Width="" Text="Age:" />
<TextBlock Height="" Margin="99,44,117,0" Name="tbUserName" Text="" VerticalAlignment="Top" />
<TextBlock Height="" Margin="99,93,117,0" Name="tbAge" Text="{Binding userInfo.Age}" VerticalAlignment="Top" />
</Grid>
</Window>

Xaml View

    public partial class MainWindow : Window
{ private RegisterUserViewModel viewModel; public MainWindow()
{
InitializeComponent(); this.ViewModel = new RegisterUserViewModel(); } public RegisterUserViewModel ViewModel
{
get
{
return this.viewModel;
}
set
{
this.viewModel = value;
this.DataContext = value;
}
}
}

View cs

    public class NotificationObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged; public void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
} public class UserInfo : NotificationObject
{
private int age; public int Age
{
get
{
return age;
} set
{
age = value;
this.RaisePropertyChanged("Age");
}
}
}

Model

最新文章

  1. Mysql调试存储过程最简单的方法
  2. UIBezierPath贝塞尔弧线常用方法记
  3. Ubuntu 系统密码相关问题
  4. Git合并开发代码分支到测试代码分支
  5. js中String.prototype.format類似于.net中的string.formitz效果
  6. python学习--抓取一个网页上图片
  7. hadoop拾遗(五)---- mapreduce 输出到多个文件 / 文件夹
  8. C++ 之高效使用STL ( STL 算法分类)
  9. Web网站与Web应用程序区别
  10. VisualStudio2013快捷键
  11. nginx前端负载,后端apache获取真实IP设置
  12. 百度之星2017初赛A轮 1001 小C的倍数问题
  13. 物体自由落体动态模拟(Linear Subspace)
  14. 基于redis的延迟消息队列设计
  15. 【转载】基于VoiceOver的移动web站无障碍访问实战
  16. css实现椭圆、半椭圆
  17. python_字符串的操作
  18. Spring cloud和Dubbo
  19. 从零开始编写自己的JavaScript框架(一)
  20. HTTP 接口响应数据解析

热门文章

  1. 秦曾昌人工智能课程---7、决策树集成学习Tree Ensembles
  2. 剑指offer——23调整数组顺序使奇数位于偶数前面
  3. Python3 多进程编程 - 学习笔记
  4. Fedora25安装mariadb并设置权限
  5. linux安装openoffice,并解决中文乱码
  6. java OOP第二章_封装
  7. Extremely fast hash algorithm-xxHash
  8. zepto(mark)
  9. String---&gt;Double 不依赖地域性的转换
  10. redis笔记_源码_跳表skiplist