我如何传递一个恒定值1多绑定绑定? [英] How can I pass a constant value for 1 binding in multi-binding?

查看:132
本文介绍了我如何传递一个恒定值1多绑定绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

<TextBlock>
    <TextBlock.Text>
        <MultiBinding Converter="{StaticResource myConverter}">
            <Binding Path="myFirst.Value" />
            <Binding Path="mySecond.Value" />
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

和我要传递例如一个固定值123,以上述两个绑定之一。我怎样才能做到这一点使用XAML?

And I want to pass a fixed value e.g. "123" to one of the two bindings above. How can I do that using XAML?

推荐答案

如果你的价值是一个简单的字符串,您可以在<$ C指定为一个常数有约束力的$ C>来源属性。如果是其他任何原始数据类型,您需要定义一个静态资源和参考本。

If your value is simply a string, you can specify it as a constant in the Source property of a binding. If it is any other primitive data type, you need to define a static resource and reference this.

定义在XAML的根 SYS 命名空间指向系统在mscorlib程序,下面应该工作方式:

Define the sys namespace in the root of the XAML to point to System in mscorlib, and the following should work:

<TextBlock>
  <TextBlock.Resources>
    <sys:Int32 x:Key="fixedValue">123</sys:Int32>
  </TextBlock.Resources>
  <TextBlock.Text>
    <MultiBinding Converter="{StaticResource myConverter}">
      <Binding Path="myFirst.Value" />
      <Binding Source="{StaticResource fixedValue}" />
    </MultiBinding>
  </TextBlock.Text>
</TextBlock>

这篇关于我如何传递一个恒定值1多绑定绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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