wpf update binding 属性 on converter 属性 change

wpf update binding property on converter property change

我有一个 TextBlock,它的前景 属性 与 MultiBinding 绑定如下:

<TextBlock.Foreground>
    <MultiBinding Converter="{StaticResource BlToBrshConv1}">
        <Binding Path="SomePropertyOfOwnerClass" />
        <Binding Path="AnotherProperty"/>
    </MultiBinding>
</TextBlock.Foreground>

转换器BlToBrshConv1如下:

Class BlToBrshConv1
 Implements IMultiValueConverter  
Property InheritedBrush as Brush
Public Function Convert(values() As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IMultiValueConverter.Convert
    Try
        Dim b1 As Boolean = CBool(values(0))     
        Dim b2 As Boolean = CBool(values(1))     
        If b1 = True AndAlso b2 = True Then
            ' Return SomeBrush0
        ElseIf b1 Then     
            '  Return SomeBrush1
        Else
            Return InheritedBrush
        End If
    Catch ex As Exception
        Return InheritedBrush
    End Try

现在我的问题是转换器本身的属性'InheritedBrush',我需要更新'Foreground'刷

前景画笔不会更新,因为绑定属性("SomePropertyOfOwnerClass" 和 "AnotherProperty")没有改变。

有什么想法吗?

您可以使用触发器更改绑定。

<TextBlock>
    <TextBlock.Style>
        <Style TargetType="TextBlock">
            <Setter Property="Foreground" Value="{Binding Defaultbrush}"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding SomePropertyOfOwnerClass}">
                    <Setter Property="Foreground" Value="{Binding SomeBrush1}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding AnotherProperty}">
                    <Setter Property="Foreground" Value="{Binding InheritedBrush}"/>
                </DataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding SomePropertyOfOwnerClass}" Value="True"/>
                        <Condition Binding="{Binding AnotherProperty}" Value="True"/>
                    </MultiDataTrigger.Conditions>
                    <Setter Property="Foreground" Value="{Binding SomeBrush0}"/>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>