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

c# - 如何在一行的PropertyChanges上调用StyleSelector,第1张

我有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

感谢。

最佳答案:

1 个答案:

答案 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"/>
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复