WPF MultiBinding - UnsetValue Issue
Asked Answered
T

2

9

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?

Tanh answered 29/6, 2010 at 9:24 Comment(0)
L
14

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>
Lovett answered 29/6, 2010 at 9:28 Comment(1)
thank you, saved me ages I already spent a lot of time searching.Tanh
H
0

For multibinding, I used below code and worked for me :

<MultiBinding Converter="{StaticResource ValueToAngle}" StringFormat="{}{0} {1}">
                        <MultiBinding.Bindings>
                            <Binding RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}" Path="TotalSkidCount"/>
                            <Binding RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type UserControl}}" Path="ActualCount"/>
                        </MultiBinding.Bindings>
                    </MultiBinding>

Below is the property of it :

public int ActualCount { get { return (int)GetValue(ActualCountProperty); } set { SetValue(ActualCountProperty, value); } }
public static readonly DependencyProperty ActualCountProperty = DependencyProperty.Register("ActualCount", typeof(int), typeof(CirculerProgressBarControl));

public int TotalSkidCount { get { return (int)GetValue(TotalSkidCountProperty); } set { SetValue(TotalSkidCountProperty, value); } }
public static readonly DependencyProperty TotalSkidCountProperty = DependencyProperty.Register("TotalSkidCount", typeof(int), typeof(CirculerProgressBarControl));
Hampshire answered 19/7, 2019 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.