9

我有一个文本块。当其 Text 绑定为:

<Binding Path="Applicant2.Surname"/>

它工作正常,但是我想包含 Forenames 所以将绑定更改为:

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

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

我怎样才能阻止这个?为什么我没有得到第一个简单绑定的问题?

4

2 回答 2

14

对于多重绑定,如果它只是空白,则需要添加一个备用值,那么您可以简单地执行以下操作:

<MultiBinding StringFormat="{}{0} {1}">
    <Binding Path="Applicant2.Forenames" FallbackValue=""/>
    <Binding Path="Applicant2.Surname" FallbackValue=""/>
</MultiBinding>
于 2010-06-29T09:28:46.347 回答
0

对于多重绑定,我使用了以下代码并为我工作:

<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>

下面是它的属性:

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));
于 2019-07-19T13:42:02.223 回答