How to call StyleSelector on PropertyChanges of a string
I have a RowStyleSelector with datagrid. He correctly caused the load on the window. On row changes when calling PropertyChange, it is not called.
<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">
This is my model:
public class TraceDataItem : ObservableObject
{
private string _newReelId;
public string NewReelId
{
get { return _newReelId; }
set
{
if (value != _newReelId)
{
_newReelId = value;
RaisePropertyChanged("NewReelId");
}
}
}
}
How can I make the RowStyleSelector
call on call PropertyChanged("NewReelId")
.
Thank.
+3
source to share
1 answer
StyleSelector
does not listen to notifications PropertyChange
. However, you can use DataTrigger
based on boolean property:
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"/>
+1
source to share