PropertyChange不在WinForms中为Nullable属性触发

时间:2017-04-12 11:08:02

标签: c# winforms inotifypropertychanged

我有一个课程经理,我已经实施了 INotifyPropertyChanged 。该类有一个可以为null的int属性。

public class Manager : INotifyPropertyChanged
    {
        private int? managerid = 0;

        public int? Managerid
        {
            get
            {
                return managerid;
            }

            set
            {
                managerid = value;
                RaisePropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged([CallerMemberName]string prop = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(prop));
        }
    }

我已将WinForm上的单个文本框绑定为:

Manager mgr = new Manager();
mgr.PropertyChanged += PropertyChanged_Mgr;
textbox.DataBindings.Add("Text", mgr, "Managerid");

以下是迷航方法:

static void PropertyChanged_Mgr(object sender, System.ComponentModel.PropertyChangedEventArgs e)

问题是如果属性可以为空,那么属性更改不会触发。如果我使所述属性不可为空,它可以正常工作。任何帮助将受到高度赞赏

0 个答案:

没有答案