WPF MultiBinding - UnsetValue Issue

2019-04-06 00:07发布

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

<Binding Path="Applicant2.Surname"/>

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>

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?

1条回答
乱世女痞
2楼-- · 2019-04-06 00:34

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>
查看更多
登录 后发表回答