[英]wpf update binding property on converter property change
I have a TextBlock which has a Foreground property bound with MultiBinding as following: 我有一个TextBlock,它具有与MultiBinding绑定的Foreground属性,如下所示:
<TextBlock.Foreground>
<MultiBinding Converter="{StaticResource BlToBrshConv1}">
<Binding Path="SomePropertyOfOwnerClass" />
<Binding Path="AnotherProperty"/>
</MultiBinding>
</TextBlock.Foreground>
The converter BlToBrshConv1 is as the following: 转换器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
Now my problem is when The property 'InheritedBrush' of the converter itself, I need to update the 'Foreground' brush. 现在我的问题是,当转换器本身的属性“ InheritedBrush”时,我需要更新“ Foreground”画笔。
The Foreground brush doesn't update because the bound properties ("SomePropertyOfOwnerClass" and "AnotherProperty") didnot change. 前景笔刷不会更新,因为绑定属性(“ SomePropertyOfOwnerClass”和“ AnotherProperty”)没有更改。
Any Ideas? 有任何想法吗?
You could change the binding using triggers. 您可以使用触发器更改绑定。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.