将多重绑定放在 xaml 的一行上 [英] putting multibinding on a single line in xaml

查看:31
本文介绍了将多重绑定放在 xaml 的一行上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法采用这种多重绑定:

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>

并且全部放在一行中,如 <TextBox IsEnabled=""/>?

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

如果是这样,我在哪里可以了解这种格式的规则?

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

推荐答案

更好(也更简单)的方法是将样式定义为可以轻松应用于任何 TextBox 的资源:

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>

这篇关于将多重绑定放在 xaml 的一行上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆