2012-05-04 2 views
0

コンバータとDataTriggerに基づいてToolkit DataGridの各行のフォアグラウンドを設定しようとしている次のXAMLコードがあります。DataTriggerは初めての評価です

コンバータは、受信したオブジェクト(IDataErrorInfoインターフェイスを実装する他のオブジェクトのコレクションを含む)を調べます。コレクションにエラーのあるアイテムがある場合、色はオレンジ色に設定され、そうでない場合は青色に設定されます。コレクションに空でない項目が含まれていない場合、色は黒に設定されます。

ここで、UIからコレクションを変更すると、すべてが正常に機能し、色が正しく設定されます。しかし、コンバータがデバッグモードで停止しないため、DataTriggerはもう評価されないようです。

私は紛失しているものを理解できません。

私のXAML:

<tk:DataGrid.RowHeaderStyle > 
<Style BasedOn="{StaticResource ResourceKey={x:Type tk:DataGridRowHeader}}" TargetType="tk:DataGridRowHeader"> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type tk:DataGridRow}}, Path=DataContext.Payload.TimeEventFunctions[0].IsEmpty}" Value="False"> 
      <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type tk:DataGridRow}}, Path=DataContext.Payload, Converter={inf:DataGridRowHeaderForegroundConverter}}" /> 
      <!--<Setter Property="Foreground" Value="DodgerBlue" />--> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

およびコンバータ:任意の助け

Public Class DataGridRowHeaderForegroundConverterExtension 
Inherits Markup.MarkupExtension 
Implements IValueConverter 

Public Overrides Function ProvideValue(serviceProvider As System.IServiceProvider) As Object 
    Return Me 
End Function 

Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert 
    Dim ret As New SolidColorBrush(Colors.Black) 
    If TypeOf value Is ISampleTableEntry Then 
     Dim ste As ISampleTableEntry = DirectCast(value, ISampleTableEntry) 
     Dim tevs As TrulyObservableCollection(Of ITimeEvFunc) = ste.TimeEventFunctions 
     If tevs.Count > 0 AndAlso Not tevs(0).IsEmpty Then 
      Dim query = From t In tevs Where t.HasErrors Select t 
      If query IsNot Nothing Then 
       Dim ErrorsPresent As Boolean = query.Count > 0 
       ret = New SolidColorBrush(Color.FromArgb(255, 255, 200, 0)) 
      Else 
       ret = New SolidColorBrush(Colors.DodgerBlue) 
      End If 
     End If 
    End If 
    Return ret 
End Function 

Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack 
    Throw New NotSupportedException 
End Function 

End Class 

感謝。

+0

XAMLで、現在使用されているものの代わりにコメント付きセッターを使用すると、すべてがうまく動作するため、非公開セッターでバインディングを使用することに関係すると思われます。 – APaglia

+0

PresentationTraceSources.TraceLevelを追加して、Bindingの詳細を確認してください。そのことに関する詳しい情報:http://bea.stollnitz.com/blog/?p=52 –

+0

クラスはINotifyPropertyChangedを実装していますか? – Paparazzi

答えて

0

私はビューモデルに「のisEmpty」プロパティのセッターをチェックする価値があると思います..あなたは "..その「のisEmpty」プロパティセッターから

をプロパティ変更イベントを発生させるとし、デフォルト値を設定して確認する必要がありますフォアグラウンド "を設定します。タグの前景のデフォルト値を設定しないでください。

+0

@Blam。それは多かれ少なかれ私がやったことです:ビューモデルでプロパティをHasErrorsプロパティをIsEmptyを使って値を取得するコレクションを参照して定義しました。その後、INotifyPropertyChangedインターフェイスを使用して、イベントをビューモデルにルーティングしました。 – APaglia