zoukankan      html  css  js  c++  java
  • INotifyPropertyChanged的使用

    C# 中的INotifyPropertyChanged

    它的作用:向客户端发出某一属性值已更改的通知。

    当属性改变时,它可以通知客户端,并进行界面数据更新.而我们不用写很多复杂的代码来更新界面数据,这样可以做到方法简洁而清晰,松耦合和让方法变 得更通用.可用的地方太多了:例如上传进度,实时后台数据变更等地方.目前我发现winform和silverlight都支持,确实是一个强大的接口.

    在构造函数中先绑定

    复制代码
    public Class_Name()
    {
        User user 
    = new User();
        user.Name 
    = "笨笨狼";
        user.Address 
    = "中国";

        textBox1.Text 
    = user.Name;
        textBox2.Text 
    = user.Address;
    }
    复制代码

    编写一个简单的业务类

    复制代码

    public class User : INotifyPropertyChanged
    {
        
    public event PropertyChangedEventHandler PropertyChanged;

        
    private string _name;
        
    public string Name
        {
            
    get { return _name; }
            
    set 
            {
                _name 
    = value;
                
    if(PropertyChanged != null)
                {
                    PropertyChanged(
    thisnew PropertyChangedEventArgs("Name"));
                }
            }
        }

        
    private string _address;
        
    public string Address
        {
            
    get { return _address; }
            
    set 
            {
                _address 
    = value;
                
    if (PropertyChanged != null)
                {
                    PropertyChanged(
    thisnew PropertyChangedEventArgs("Address"));
                }
            }
        }
    }

  • 相关阅读:
    redis使用
    ZooKeeper之service discovery
    Git环境配置
    Windows 下MySql Replication(复制)配置
    Django框架简介(MVC框架和MTV框架)
    ftp连接服务器失败||或者Xshell链接错误:Could notconnect to '192.168.18.128' (port 22): Connection failed
    git
    roles
    ansible 中的模块
    ansible 中的 playbook 模块
  • 原文地址:https://www.cnblogs.com/xwj517537691/p/2721085.html
Copyright © 2011-2022 走看看