我有RowStyleSelector和datagrid。 在窗口加载时正确调用它。 当我调用PropertyChange时,行的更改不会被调用。
PopupWindow
这是我的模特:
<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");
}
}
}
}
时调用RowStyleSelector
。
感谢。
答案 0 :(得分:1)
StyleSelector
不会收听PropertyChange
次通知。但是,您可以使用基于布尔属性的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"/>