WPF/MVVM: SelectedIndex Binding Property not updating when Combobox Selection Changed

后端 未结 1 666
借酒劲吻你
借酒劲吻你 2021-01-26 11:52

I\'ve got a very similar question to Jinesh\'s. I need to get the value of the SelectedIndex (or SelectedItem or SelectedValue) of a combo box in to my ViewMode

相关标签:
1条回答
  • 2021-01-26 12:10

    The property getter ignores the previously set value and always returns the index of the current month.

    The declaration should look like this:

    private int monthIndex = DateTime.Today.Month - 1;
    
    public int MonthIndex
    {
        get { return monthIndex; }
        set
        {
            if (monthIndex != value)
            {
                monthIndex = value;
                RaisePropertyChanged("MonthIndex");
            }
        }
    } 
    
    0 讨论(0)
提交回复
热议问题