0

コンバーターと DataTrigger に基づいて、Toolkit DataGrid の各行の前景を設定しようとしている次の XAML コードがあります。

コンバーターは、他のオブジェクトのコレクションを含む受信オブジェクトを調べ、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

助けてくれてありがとう。

4

1 に答える 1

0

ビューモデルの「IsEmpty」プロパティセッターをチェックする価値があると思います..その「IsEmpty」プロパティセッターからプロパティ変更イベントを発生させる必要があります..

そして、セッターを介してデフォルト値を「フォアグラウンド」に設定してください。タグの前景のデフォルト値を設定しないでください。

于 2012-05-04T15:27:01.327 に答える