下面是我的demo
XAML:
<DataGrid ItemsSource="{Binding}" Name="c1datagrid" AutoGenerateColumns="False" EnableRowVirtualization="True" EnableColumnVirtualization="True">
<DataGrid.Columns>
<DataGridTextColumn Header="A" Binding="{Binding A}"></DataGridTextColumn> </DataGrid.Columns>
</DataGrid>
CS:
声明两个集合:
ObservableCollection<test1> ls;
ObservableCollection<test1> cc;
this.c1datagrid.DataContext = ls;
初始化的时候赋值,并绑定给datacontext;
private void button2_Click(object sender, RoutedEventArgs e)
{
ls = cc;
}
点击按钮给集合切换内容,但是界面不变化
ls=cc之后,DataContext和ls已经不指向一个对象了
我弱智了,是滴
学到了,谢谢