INotifyPropertyChanged in WPF

后端 未结 2 1814
梦毁少年i
梦毁少年i 2021-01-19 21:39

Try to understand WPF. This is my test classes:

    public partial class MainWindow : Window, INotifyPropertyChanged
{
    private ObservableCollection

        
2条回答
  •  耶瑟儿~
    2021-01-19 21:58

    The problem is that you are directly setting the original list onto the Window.DataContext, so nothing ever listens to the windows' PropertyChanged event.

    To solve this, set the DataContext to the window itself:

    this.DataContext = this;
    

    and then change the Binding so refer to the property:

    
    

    You will also need to change your property definition so that it raises the name of the property being changed, not the name of the member:

    this.RaisePropertyChanged("MyList");
    

提交回复
热议问题