zoukankan      html  css  js  c++  java
  • Silverlight 2.0 beta 2学习笔记(2)

    重要的很有用的接口:

    INotifyPropertyChanged

    功能:

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


    只有一个事件:PropertyChanged

    在更改属性值时发生。



    示例:
    // This class implements a simple customer type 
    // that implements the IPropertyChange interface.
    public class DemoCustomer : INotifyPropertyChanged
    {
        
    // These fields hold the values for the public properties.
        private Guid idValue = Guid.NewGuid();
        
    private string customerName = String.Empty;
        
    private string companyNameValue = String.Empty;
        
    private string phoneNumberValue = String.Empty;

        
    public event PropertyChangedEventHandler PropertyChanged;
        
        
    private void NotifyPropertyChanged(String info)
        
    {
            
    if (PropertyChanged != null)
            
    {
                PropertyChanged(
    thisnew PropertyChangedEventArgs(info));
            }

        }


        
    // The constructor is private to enforce the factory pattern.
        private DemoCustomer()
        
    {
            customerName 
    = "no data";
            companyNameValue 
    = "no data";
            phoneNumberValue 
    = "no data";
        }


        
    // This is the public factory method.
        public static DemoCustomer CreateNewCustomer()
        
    {
            
    return new DemoCustomer();
        }


        
    // This property represents an ID, suitable
        
    // for use as a primary key in a database.
        public Guid ID
        
    {
            
    get
            
    {
                
    return this.idValue;
            }

        }


        
    public string CompanyName
        
    {
            
    get
            
    {
                
    return this.companyNameValue;
            }


            
    set
            
    {
                
    if (value != this.companyNameValue)
                
    {
                    
    this.companyNameValue = value;
                    NotifyPropertyChanged(
    "CompanyName");
                }

            }

        }


        
    public string PhoneNumber
        
    {
            
    get
            
    {
                
    return this.phoneNumberValue;
            }


            
    set
            
    {
                
    if (value != this.phoneNumberValue)
                
    {
                    
    this.phoneNumberValue = value;
                    NotifyPropertyChanged(
    "PhoneNumber");
                }

            }

        }

    }
  • 相关阅读:
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    第三章预习笔记-运算方法和运算部件
    非数值数据的编码表示
  • 原文地址:https://www.cnblogs.com/boywujch/p/1238651.html
Copyright © 2011-2022 走看看