2015-06-14 43 views
3

我有RowStyleSelector與數據網格。 窗口加載時調用正確。 當我調用PropertyChange時不會調用行的更改。如何調用行PropertyChanges StyleSelector

<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"); 
      } 
     } 
    } 


} 

我怎樣才能讓RowStyleSelectorPropertyChanged("NewReelId")被稱爲被調用。

謝謝。

回答

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

完美,由於它解決了我的問題。 –

+0

不客氣=) –