gpt4 book ai didi

c# - 如何在一行的 PropertyChanges 上调用 StyleSelector

转载 作者:行者123 更新时间:2023-11-30 17:43:30 25 4
gpt4 key购买 nike

我有带数据网格的 RowStyleSelector。它在窗口加载时被正确调用。在我调用 PropertyChange 时更改行时它不会被调用。

<DataGrid Grid.Row="2" ColumnWidth="*"  ItemsSource="{Binding TraceItemCollectionViewSource , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}" EnableRowVirtualization="false"  RowStyleSelector="{StaticResource TraceRowStyleSelector}" IsReadOnly="True" Name="TraceDataGrid" Margin="5,5,5,5" Padding="5,5,5,5" AutoGenerateColumns="False">

这是我的模型:

public class TraceDataItem :  ObservableObject
{

private string _newReelId;
public string NewReelId
{
get { return _newReelId; }
set
{
if (value != _newReelId)
{
_newReelId = value;
RaisePropertyChanged("NewReelId");
}
}
}


}

如何在调用 PropertyChanged("NewReelId") 时调用 RowStyleSelector

谢谢。

最佳答案

StyleSelector 不监听 PropertyChange 通知。但是,您可以改用基于 bool 属性的 DataTrigger:

bool _reelIdChanged;
public bool ReelIdChanged
{
get { return _reelIdChanged; }
set
{
_reelIdChanged = value;
RaisePropertyChanged("ReelIdChanged");
}
}

private string _newReelId;
public string NewReelId
{
get { return _newReelId; }
set
{
if (value != _newReelId)
{
_newReelId = value;
ReelIdChanged = true;
RaisePropertyChanged("NewReelId");
}
else
ReelIdChanged = false;
}
}

XAML:

<Window.Resources>
<Style TargetType="DataGridRow" x:Key="TraceRowStyle">
<Setter Property="Background" Value="{DynamicResource DataBackground}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=ReelIdChanged }" Value="True">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>

...

    <DataGrid Grid.Row="0" 
ColumnWidth="*"
ItemsSource="{Binding TraceItemCollectionViewSource , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}"
EnableRowVirtualization="false"
RowStyle="{StaticResource TraceRowStyle}"
IsReadOnly="True"
Name="TraceDataGrid"
Margin="5,5,5,5"
Padding="5,5,5,5"
AutoGenerateColumns="False"/>

关于c# - 如何在一行的 PropertyChanges 上调用 StyleSelector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30827577/

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