コンバータと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
感謝。
XAMLで、現在使用されているものの代わりにコメント付きセッターを使用すると、すべてがうまく動作するため、非公開セッターでバインディングを使用することに関係すると思われます。 – APaglia
PresentationTraceSources.TraceLevelを追加して、Bindingの詳細を確認してください。そのことに関する詳しい情報:http://bea.stollnitz.com/blog/?p=52 –
クラスはINotifyPropertyChangedを実装していますか? – Paparazzi