当前位置:   article > 正文

WPF入门第六篇 界面绑定属性刷新 INotifyPropertyChanged_inotifypropertychanged wpf

inotifypropertychanged wpf

前言

本文是wpf入门系列第五篇,面向有winform或者web前端基础的、并且也有C#基础的同学。

本文简单的介绍了 WPF 中界面绑定值得刷新问题, INotifyPropertyChanged 的作用及用法,以及对它的封装使用。其中,封装使用参考了WPF的开源框架ReactiveUI。

本文使用了 Visual Studio 2017 进行演示讲解。

wpf入门系列导航页面: https://blog.csdn.net/wf824284257/article/details/88757497

上一步: wpf入门第五篇 WPF with ECharts
https://blog.csdn.net/wf824284257/article/details/89002133

学习本文之前,推荐先学习这篇: wpf入门第二篇 MVVM与binding
https://blog.csdn.net/wf824284257/article/details/88758707

开始

step.1 创建示例项目

打开 VS2017,新建WPF项目,命名为 VMTest (VM是ViewModel的简称).

################ 1

在解决方案资源管理器中右键点击我们的项目,选择【添加】->【类】,添加一个Person类。

################ 2

将Person.cs代码替换为如下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VMTest
{
    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

将MainWindow.xaml代码替换为下面代码:

<Window x:Class="VMTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x=
  • 1
  • 2
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/567795
推荐阅读
相关标签
  

闽ICP备14008679号