WPF MultiBinding - UnsetValue问题 [英] WPF MultiBinding - UnsetValue Issue

查看:500
本文介绍了WPF MultiBinding - UnsetValue问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextBlock。当它的文本绑定为:

I have a TextBlock. When its Text is bound as:

<Binding Path="Applicant2.Surname"/>

它工作得很好,不过,我想包括Forenames改变,以便结合:

It works fine, however I want to include the Forenames so changed the binding to:

<MultiBinding StringFormat="{}{0} {1}">
    <Binding Path="Applicant2.Forenames"/>
    <Binding Path="Applicant2.Surname"/>
</MultiBinding>

这显示{DependencyProperty.UnsetValue} {} DependencyProperty.UnsetValue直到值设置的第一次。

This displays {DependencyProperty.UnsetValue} {DependencyProperty.UnsetValue} until the value is set the first time.

我怎样才能停止?为什么我不能与第一个简单绑定的问题?

How can I stop this? Why do I not get the problem with the first simple binding?

推荐答案

对于multibinding你需要添加一个备用的值,如果它仅仅是空白的,那么你可以简单地做:

for a multibinding you need to add a fallback value if it is just blank then you can simply do:

<MultiBinding StringFormat="{}{0} {1}">
    <Binding Path="Applicant2.Forenames" FallbackValue=""/>
    <Binding Path="Applicant2.Surname" FallbackValue=""/>
</MultiBinding>

这篇关于WPF MultiBinding - UnsetValue问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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