我有一个TextBlock。当其文本绑定为:
<Binding Path="Applicant2.Surname"/>
它工作正常,但是我想要包含Forenames,因此将绑定更改为:
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Applicant2.Forenames"/>
<Binding Path="Applicant2.Surname"/>
</MultiBinding>
显示{DependencyProperty.UnsetValue} {DependencyProperty.UnsetValue},直到第一次设置该值。
我怎么能阻止这个?为什么我没有遇到第一个简单绑定的问题?
答案 0 :(得分:14)
对于多重绑定,如果只是空白,则需要添加一个后备值,然后您可以执行以下操作:
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Applicant2.Forenames" FallbackValue=""/>
<Binding Path="Applicant2.Surname" FallbackValue=""/>
</MultiBinding>
答案 1 :(得分: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));