WPF DataGrid 未拾取 CollectionChanged 事件?
所以我有这个 DataGrid:
<DataGrid d:DataContext="{d:DesignData Source=../DesignData/ValidationMessages.xaml}" DataContext="{Binding Messages, Mode=OneWay}" ItemsSource="{Binding Mode=OneWay}" Name="Grid">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Message}" Header="Message"/>
<DataGridTextColumn Binding="{Binding ControlID}" Header="ID"/>
</DataGrid.Columns>
</DataGrid>
我有这个属性:
public ObservableCollection<ValidationMessage> Messages = new ObservableCollection<ValidationMessage>();
我有这个代码:
Messages.Add(message);
并且 DataGrid 不显示更改。应该是吧?我觉得我已经这样做了一百万次,但由于某种原因它不起作用。
我已将整个控件的 DataContext 设置为其自己的代码隐藏,但没有运气。我尝试过修改绑定的 BindingMode,但什么也没有。
当我在执行期间检查 DataGrid 时,它显示项目计数为 0。
有人知道我做错了什么,或者我可以尝试什么?
So I have this DataGrid:
<DataGrid d:DataContext="{d:DesignData Source=../DesignData/ValidationMessages.xaml}" DataContext="{Binding Messages, Mode=OneWay}" ItemsSource="{Binding Mode=OneWay}" Name="Grid">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Message}" Header="Message"/>
<DataGridTextColumn Binding="{Binding ControlID}" Header="ID"/>
</DataGrid.Columns>
</DataGrid>
and I have this property:
public ObservableCollection<ValidationMessage> Messages = new ObservableCollection<ValidationMessage>();
and I have this code:
Messages.Add(message);
And the DataGrid doesn't show changes. It should, right? I feel like I've done this a million times, but for some reason it's not working.
I have set the DataContext of the whole control to be its own code-behind, no luck. I've tried messing with the BindingMode of the bindings, nothing.
When I inspect the DataGrid during execution, it shows the Items count to be 0.
Anyone know what I am doing wrong, or what I can try?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你的代码有什么问题,但这有效。
I don't know what is wrong with your code but this works.