本文介绍了把multibinding在XAML一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法借此multibinding:

Is there a way to take this multibinding:

<TextBox.IsEnabled>
    <MultiBinding Converter="{StaticResource LogicConverter}">
        <Binding ElementName="prog0_used" Path="IsEnabled" />
        <Binding ElementName="prog0_used" Path="IsChecked" />
    </MultiBinding>
</TextBox.IsEnabled>

和投入都是在同一行,如&LT;文本框IsEnabled =/&GT;

and put is all on one line, as in <TextBox IsEnabled="" />?

如果是这样,我在哪里可以学习这formattiong规则?

If so, where can I learn the rules of this formattiong?

推荐答案

一个更好的(和简单)的方法是定义一个样式作为一个资源,你可以很容易地应用到任何文本框:

A better (and simpler) approach would be to define a style as a resource which you can easily apply to any TextBox:

<Window.Resources>
    <c:MyLogicConverter x:Key="LogicConverter" />

    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}" x:Key="MultiBound">
        <Setter Property="IsEnabled">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource LogicConverter}">
                    <Binding ElementName="switch" Path="IsEnabled" />
                    <Binding ElementName="switch" Path="IsChecked" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<StackPanel Orientation="Horizontal">
    <CheckBox Name="switch" />
    <TextBox Name="textBox2" Text="Test" Style="{StaticResource MultiBound}" />
</StackPanel>

这篇关于把multibinding在XAML一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 07:34