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");
                }

            }

        }

    }
  • 相关阅读:
    php抽象与接口的区别[转载]
    PHP基础知识(一)
    HTML/CSS方法实现下拉菜单
    SQL语句详细汇总[转]
    (5) 控制器和状态
    (4)模型和数据
    (3)理解代理 proxy
    (2)基于原型的类继承
    (1) basic javascript class
    观察者模式
  • 原文地址:https://www.cnblogs.com/boywujch/p/1238651.html
Copyright © 2011-2022 走看看