5
我使用了一个标准的.NET的DataGrid这样的:棱镜/ MVVM:绑定列到DataGrid中
<DataGrid ItemsSource="{Binding Datensaetze}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="my col 1" Binding="{Binding MyCol1}"/>
<DataGridTextColumn Header="my col 2" Binding="{Binding MyCol2}"/>
<DataGridTextColumn Header="my col 3" Binding="{Binding MyCol3}"/>
</DataGrid.Columns>
</DataGrid>
这是工作很好。现在我想定义ViewModel中的列,而不是在xaml中设置固定列,我想在运行中生成它们。但是,如果我尝试将列与任何东西绑定,则会出现错误,并说
DataGrid.Columns是只读属性,无法绑定。
有没有办法将DataGrid列动态绑定到代码背后的东西?
我一直在使用这很好,但我碰到的,我需要更新在后台线程中的ObservableCollection问题(我使用Dispatcher来做到这一点)。上面的代码然后在CollectionChanged委托中出现错误“调用线程无法访问此对象,因为不同的线程拥有它”。任何建议我可以做什么? – 2013-01-30 15:55:46