带有转换器的多绑定的XAML字符串格式 [英] XAML string format in multibinding w/converter
本文介绍了带有转换器的多绑定的XAML字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在实现此TextBlock,并且没有出现 stringformat ,只有绑定属性的值出现了.你能告诉我我在做什么错吗?
I am implementing this TextBlock and the stringformat is not appearing, only the value of the binding property. Can you tell me what I'm doing wrong?
XAML代码
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ResourceKey=myConverter}">
<Binding Path="loc.country" StringFormat="Country: {0}"/>
<Binding Path="loc.area" StringFormat="Area: {0}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
转换器
public class MyMultiConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[1] == null)
return values[0];
return values[1];
}
public object[] ConvertBack(object values, Type[] targetType, object parameter, CultureInfo culture)
{
return null;
}
}
最诚挚的问候,
推荐答案
查看全文