Stringformat 连接数据绑定和资源的值 [英] Stringformat concatenates databinding and resource's value
问题描述
我想在我的窗口标题中连接一个来自我的视图模型的属性和一个来自资源文件的值.这是我在没有资源字符串的情况下所做的工作:
Title="绑定路径=描述,StringFormat=建筑:{0}}"
现在我想删除Building"字符串并从资源中放置一个值,就像我在其他地方使用的一样:
xmlns:res="clr-namespace:Project.View.Resources"{res:Strings.TitleDescription}
我如何定义两者?我可以像 {1} 参数一样定义吗?
是的,你可以.只需使用 MultiBinding
.>
关于 StringFormat
有一个例子.
在您的情况下,代码如下所示:
<TextBlock.Text><MultiBinding StringFormat="{}{0} {1}"><Binding Source="{x:Static res:Strings.TitleDescription}"/><绑定路径=说明"/></多重绑定></TextBlock.Text></TextBlock>
I want to concatenate in my window title a property from my viewmodel and a value that cames from a resources file. This is what I have working without the string from resources:
Title="Binding Path=Description, StringFormat=Building: {0}}"
Now I want to remove the "Building" string and put a value from a resource like I use on other places:
xmlns:res="clr-namespace:Project.View.Resources"
{res:Strings.TitleDescription}
How can I define both? Can I define like a {1} parameter?
Yes, you can. Simply use a MultiBinding
.
The MSDN article on StringFormat
has an example.
In your case, the code would look something like this:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Source="{x:Static res:Strings.TitleDescription}"/>
<Binding Path="Description"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
这篇关于Stringformat 连接数据绑定和资源的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!