WPF DataGrid not updating on PropertyChanged

前端 未结 3 816
离开以前
离开以前 2021-01-11 11:27

i\'ve a problem updating my datagrid when clicking the button by using NotifyPropertyChanged. It works if i set the DataGrid.ItemsSource in code behind, but it doesn\'t if i

3条回答
  •  囚心锁ツ
    2021-01-11 12:06

    In your codebehind .xaml.cs create property

       public ObservableCollection MyCollection {get; set;}
    
       private void Window_Loaded(object sender, RoutedEventArgs e)
       {
        //if i set the ItemsSource here, updating of the UI works
          dataGrid1.ItemsSource = MyCollection;
       }
    

    In XAML:

       
    

提交回复
热议问题