добавление нового события PropertyChanged в форму - PullRequest
0 голосов
/ 27 октября 2011
    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;
.
.
.

и я добавил

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

внутри InitializeComponent метод ..


Теперь, когда я открываю конструктор enter image description here

Я нажал Ignore and Continue, все работало нормально ..

Теперь, когда я снова закрываю и открываю решение, код EventHandler, введенный в InitializeComponent, отсутствует.

В чем проблема?

1 Ответ

1 голос
/ 27 октября 2011

Посмотрите на это:

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

Там есть ответ. Поместите ваш код в конструктор ниже InitializeComponent();.

...