How to update a data bound combobox when the source data changes?

安稳与你 提交于 2019-12-05 16:14:37

Try implementing INotifyPropertyChanged in your Range class:

public class Range : INotifyPropertyChanged
{
    // Declare the event
    public event PropertyChangedEventHandler PropertyChanged;
    private string _range_name;
    private string _range_description;
    private int _min;
    private int _max;

    public string range_name
    {
        get { return this._range_name; }
        set
        {
            _range_name = value;
            OnPropertyChanged("range_name");  
        }  // Call OnPropertyChanged whenever the property is updated
    }
    public string range_description
    {
        get { return this._range_description; }
        set
        {
            _range_description = value;
            OnPropertyChanged("range_description");
        }
    }
    public int min
    {
        get { return this._min; }
        set
        {
            _min=value;
            OnPropertyChanged("min");
        }
    }
    public int max
    {
        get { return this._max; }
        set
        {
            _max = value;
            OnPropertyChanged("max");
        }
    }

    // Create the OnPropertyChanged method to raise the event
    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }
}

Hope it helps ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!