Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何访问应用程序资源中定义的多重绑定_C#_Wpf_Xaml - Fatal编程技术网

C# 如何访问应用程序资源中定义的多重绑定

C# 如何访问应用程序资源中定义的多重绑定,c#,wpf,xaml,C#,Wpf,Xaml,我想重用多重绑定并尝试使用,但我似乎无法从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"

我想重用多重绑定并尝试使用,但我似乎无法从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>这两次尝试将无法编译:

<TextBox IsEnabled="{StaticResource OnOffBinding}"/>
<TextBox IsEnabled="{MultiBinding {StaticResource OnOffBinding}}" />

有什么想法吗


编辑:在接受Funcs答案后,我想这已经在链接的线程中得到了回答。抱歉..

请尝试将其包装成时尚的样式

<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”
将其设置为通用。

Style=“{StaticResource ControlEnabler}”将为您提供无效的强制转换。正如我写的那样,我已经尝试过这种方法,如果你尝试在地方层面上这样做,你会发现你无法从一个设定者那里获得IsEnabledProperty@noontz它起作用了,试过了。您的多重绑定需要返回布尔值。谢谢您的努力。你能给我看看你的BooleanMultiConverter的代码吗?我返回一个布尔值,但我甚至无法编译您的app.xaml代码段:x:Key=“OnOffBinding”部分上的错误MC3032在这里也起作用。。Donno以前怎么了,但现在我有了我不想要的,而且我的问题似乎是多余的。。谢谢