我想重复使用MultiBinding并尝试使用this solution,但我似乎无法从Setter属性中获取IsEnabled。
所以我尝试了这种方法,但没有雪茄:
的App.xaml
<Application x:Class="Test.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:model="clr-namespace:Test.MODEL"
StartupUri="MainWindow.xaml">
<Application.Resources>
<view:BooleanConverter x:Key="BooleanConverter" />
<view:BooleanMultiConverter x:Key="BooleanMultiConverter" />
<MultiBinding x:Key="OnOffBinding" Converter="{StaticResource BooleanMultiConverter}" ConverterParameter="OR">
<Binding Path="model:CustomerIsDefined" Converter="{StaticResource BooleanConverter}" />
<Binding Path="model:CustomerIsConfirmed" Converter="{StaticResource BooleanConverter}" />
</MultiBinding>
</Application.Resources>
MainWindow.xaml&gt;这两次尝试都不会编译:
<TextBox IsEnabled="{StaticResource OnOffBinding}"/>
<TextBox IsEnabled="{MultiBinding {StaticResource OnOffBinding}}" />
有什么想法吗?
编辑:接受Funcs回答后我猜这已经在链接线程中得到了解答。抱歉..
答案 0 :(得分:2)
尝试将其包装在Style
中<Application.Resources>
<view:BooleanConverter x:Key="BooleanConverter" />
<view:BooleanMultiConverter x:Key="BooleanMultiConverter" />
<Style x:Key="ControlEnabler" TargetType="Control">
<Setter Property="IsEnabled">
<Setter.Value>
<MultiBinding x:Key="OnOffBinding" Converter="{StaticResource BooleanMultiConverter}" ConverterParameter="OR">
<Binding Path="model:CustomerIsDefined" Converter="{StaticResource BooleanConverter}" />
<Binding Path="model:CustomerIsConfirmed" Converter="{StaticResource BooleanConverter}" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
MainWindow.xaml
<TextBox Style="{StaticResource ControlEnabler}"/>
注意TargetType="Control"
使其成为通用。