C# 向窗体添加新的PropertyChanged事件

C# 向窗体添加新的PropertyChanged事件,c#,winforms,events,enums,inotifypropertychanged,C#,Winforms,Events,Enums,Inotifypropertychanged,我补充说 public partial class FrmEditSiteParticulars : Form, INotifyPropertyChanged { public enum EntryTypes { Undefined, Site, Particular } private EntryTypes _EntryType; private EntryTypes EntryTyp

我补充说

    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;
.
.
.
内部
初始化组件
方法


现在当我打开设计器时

我单击了“忽略并继续”
,效果很好

现在,当我再次关闭并打开解决方案时,我放在
InitializeComponent
中的eventHandler代码丢失了

有什么问题吗?

看看这个:

this.EntryTypeChanged += new 
     System.ComponentModel.PropertyChangedEventHandler(this.EntryType_Changed);
//
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()

答案就在这里。将代码放入构造函数中,在
InitializeComponent()下面

您的观察和解决方案的方法非常出色:)
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()