目的是在不同的地方重用这个 MultiBinding
<MultiTrigger.Conditions>
<Condition Value="True">
<Condition.Binding>
<MultiBinding Converter="{StaticResource ValidationBooleanConverter}">
<Binding X" />
<Binding Y" />
<Binding Z" />
</MultiBinding>
</Condition.Binding>
</Condition>
</MultiTrigger.Conditions>
当前不太干燥的条件 (n+)
<Style x:Key="AnErrorTemplate" TargetType="FrameworkElement">
<Style.Triggers>
<MultiTrigger>
<!-- Repeating the whole MultiTrigger.Conditions block here --->
<Setter Property="Validation.ErrorTemplate" Value="{StaticResource DirtyErrorControlTemplate}" />
</MultiTrigger>
</Style.Triggers>
<Style x:Key="AnotherStyle" TargetType="FrameworkElement">
<Style.Triggers>
<MultiTrigger>
<!-- Repeating the whole MultiTrigger.Conditions block here --->
<Setter Property="Other" Value="SomeValueIfTheSameConditionsAreTrue" />
</MultiTrigger>
</Style.Triggers>
事实上,要求更广泛,因为我还需要在 ControlTemplates 中重复使用这些相同的条件。
<ControlTemplate x:Key="InlineErrorControlTemplate" TargetType="{x:Type Control}">
<TextBlock Text="{Binding ElementName=InputView, Path=(Validation.Errors)[0].ErrorContent}" Foreground="Red"/>
<ControlTemplate.Triggers>
<MultiTrigger>
<!-- Repeating the whole MultiTrigger.Conditions block here --->
<Setter Property="Visibility" Value="SetMeIfTheseSameTriggerConditionsHold" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
易于维护的雨伞?
有什么想法可以只指定一次 MultiTrigger.Conditions 或 MultiBinding,然后在多个样式和控件模板中使用它吗?
- 仅在 XAML 中?