2011-10-27 22 views
0
public partial class FrmEditSiteParticulars : Form, INotifyPropertyChanged 
    { 

    public enum EntryTypes 
    { 
     Undefined, 
     Site, 
     Particular 
    } 

    private EntryTypes _EntryType; 

    private EntryTypes EntryType { 
     get{return _EntryType;} 
     set 
     { 
      if (value != _EntryType) 
      { 
       _EntryType = value; 
       OnPropertyChanged("EntryType"); 
      } 
     } 
    } 

    public event PropertyChangedEventHandler EntryTypeChanged; 

    protected void OnPropertyChanged(string propertyName) 
    { 
     PropertyChangedEventHandler handler = EntryTypeChanged; 
     if (handler != null) 
      handler(this, new PropertyChangedEventArgs(propertyName)); 
    } 
. 
. 
. 
    public event PropertyChangedEventHandler PropertyChanged; 
. 
. 
. 

和我說增加新的PropertyChanged事件到窗體

this.EntryTypeChanged += new 
    System.ComponentModel.PropertyChangedEventHandler(this.EntryType_Changed); 

InitializeComponent方法..


現在,當我打開Designer enter image description here

我點擊Ignore and Continue,它工作很好..

現在,當我關閉並重新打開該解決方案,我把在InitializeComponent的事件處理程序代碼丟失..

問題是什麼?

回答

1

看看這個:

/// <summary> 
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor. 
/// </summary> 
private void InitializeComponent() 

有答案。把你的代碼放在構造函數中,低於InitializeComponent();

+0

您的觀察和解決方案是一流的.. :) – dotNETbeginner