内容更改时 DataGridView 样式不更新
好的,这是我的情况: 我有一个包含 Message
的 DataGridView,其中应用了以下样式。
<Style x:Key="ChangeSetRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsRead}" Value="False">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding IsRead}" Value="True">
<Setter Property="FontWeight" Value="Normal" />
</DataTrigger>
</Style.Triggers>
</Style>
我的目的是使未读消息加粗,而已读消息保持正常字体粗细。尽管在加载集合时正确应用了样式,但当更改项目的 IsRead
属性时,不会发生任何变化。风格好像没有更新。
有人可以解释一下吗?谢谢!
Ok, here is my situation:
I have a DataGridView
containing Message
s, to which the following style is applied.
<Style x:Key="ChangeSetRowStyle" TargetType="{x:Type DataGridRow}">
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsRead}" Value="False">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
<DataTrigger Binding="{Binding IsRead}" Value="True">
<Setter Property="FontWeight" Value="Normal" />
</DataTrigger>
</Style.Triggers>
</Style>
My intention is to make unread messages bold, while read messages stay with normal font weight. Even though the style is applied correctly when the collection is loaded, nothing changes when an item's IsRead
property is changed. It seems like the style just does't update.
Can someone please shed some light on this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的
Message
类需要从INotifyPropertyChanged
继承,并且IsRead
属性需要在修改时引发PropertyChanged
事件。这是一个例子:Your
Message
class needs to inherit fromINotifyPropertyChanged
and theIsRead
property needs to raise thePropertyChanged
event when modified. Here's an example:我的猜测是,当 IsRead 属性更改时,您的 Message 类不会引发 OnPropertyChanged 事件。以下是如何执行此操作的简单示例:
http://msdn.microsoft。 com/en-us/library/ms743695.aspx
My guess would be that your Message class is not raising an OnPropertyChanged event when the IsRead property is changed. Here is a simple example of how you do this:
http://msdn.microsoft.com/en-us/library/ms743695.aspx
您必须指定何时刷新绑定值:
将
UpdateSourceTrigger
指定为PropertyChanged
将在每次IsRead
的值更改时更新该值。You have to specify when you want the binding value to be refreshed:
Specifying
UpdateSourceTrigger
toPropertyChanged
will update the value each timeIsRead
's value changes.