如何将多个值绑定到一个WPF TextBlock的? [英] How to bind multiple values to a single WPF TextBlock?

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

问题描述

我目前使用的的TextBlock 下面一个名为名称属性的值绑定:

I'm currently using the TextBlock below to bind the value of a property named Name:

<TextBlock Text="{Binding Name}" />

现在,我要绑定的其他的命名属性 ID 相同的的TextBlock

Now, I want to bind another property named ID to the same TextBlock.

是否有可能两个或多个值绑定到同一的TextBlock ?它可以用简单的拼接来完成,如名称+ ID ,如果没有,怎么回事会这样走近?

Is it possible to bind two or more values to the same TextBlock? Can it be done with simple concatenation, like Name + ID and, if not, how else could this be approached?

推荐答案

您可以使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.data.multibinding.aspx\"><$c$c>MultiBinding结合<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx\"><$c$c>StringFormat属性。用法将类似于以下内容:

You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following:

<TextBlock>
    <TextBlock.Text>    
        <MultiBinding StringFormat="{}{0} + {1}">
            <Binding Path="Name" />
            <Binding Path="ID" />
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

由于的名称以及对 1 您在TextBlock的输出将ID值的值美孚+ 1

Given a value of Name of Foo and a value for ID of 1 you output in the TextBlock would be Foo + 1.

注: 的,这是只支持.NET 3.5 SP1和3.0 SP2或更高版本。

Note: that this is only supported in .NET 3.5 SP1 and 3.0 SP2 or later.

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

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