C# 在textblock中绑定路径值为null时设置另一个值
在我的Source2属性中,我有一个textblock作为文本块中的显示名称 Property1为空,然后显示Property2C# 在textblock中绑定路径值为null时设置另一个值,c#,silverlight,binding,C#,Silverlight,Binding,在我的Source2属性中,我有一个textblock作为文本块中的显示名称 Property1为空,然后显示Property2 <TextBlock x:Name="txtName" Text="{Binding Property1 , Mode=OneWay, Converter={StaticResource DataConvertor}, ConverterParameter=lblDisplayName,TargetNullValue={Binding Path=Property
<TextBlock x:Name="txtName" Text="{Binding Property1 , Mode=OneWay, Converter={StaticResource DataConvertor}, ConverterParameter=lblDisplayName,TargetNullValue={Binding Path=Property ,Mode=OneWay}}"></TextBlock>
但它在运行时会给我错误
通过查看此代码,很难说出您在这里要做什么 但我建议您处理这是您的视图模型
private string _property1;
public string Property1
{
get{
return _property1;
}
set
{
Property1 = value;
OnPropertyChanged("Property1");
}
}
private string _property2;
public string Property2
{
get{
return _property2;
}
set
{
if(value!=null)
{
Property2 = value;
}else
{
Property2 = Property1;
}
OnPropertyChanged("Property2");
}
}
我得到了答案,但方式不同
<TextBlock x:Name="txtName" Text="{Binding Mode=OneWay, Converter={StaticResource DataConvertor}, ConverterParameter=lblName}" VerticalAlignment="Bottom" FontWeight="Bold" ></TextBlock>
我不会为绑定指定任何特定属性,也不会从转换器中指定值,谢谢您的回答,但我认为使用转换器类ans可以指定第二个属性,而不是更改属性值