gpt4 book ai didi

wpf - DataGridView 样式在内容更改时不更新

转载 作者:行者123 更新时间:2023-12-04 06:26:37 24 4
gpt4 key购买 nike

好的,这是我的情况:
我有一个 DataGridView包含 Message s,应用以下样式。

<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 时没有任何变化。属性改变了。好像样式只是没有更新。

有人可以对此有所了解吗?谢谢!

最佳答案

您的 Message类需要继承自 INotifyPropertyChangedIsRead属性(property)需要提高PropertyChanged修改时的事件。下面是一个例子:

public class Message: INotifyPropertyChanged
{
private bool _isRead;

public bool IsRead
{
get { return _isRead; }
set
{
_isRead = value;
RaisePropertyChanged("IsRead");
}
}


#region INotifyPropertyChanged Members

/// <summary>
/// Raised when a property on this object has a new value.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;

#endregion

/// <summary>
/// Raises this object's PropertyChanged event.
/// </summary>
/// <param name="propertyName">The property that has a new value.</param>
public virtual void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
}

关于wpf - DataGridView 样式在内容更改时不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5977778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com