Wpf 在标签上显示标准文本?
我有这个标签:Wpf 在标签上显示标准文本?,wpf,xaml,Wpf,Xaml,我有这个标签: <Label Content="{Binding MatchController.Match.Competition}" ContentStringFormat="League: {0}"/> 我需要每次显示值League:无论如何,如果该值未绑定,我看不到任何联盟:在gui上,如何解决此问题?请确保ViewModel或Bind属性返回null或空字符串,或使用单独的标签您可以使用适当的ContentTemplate: <Label Content="{B
<Label Content="{Binding MatchController.Match.Competition}" ContentStringFormat="League: {0}"/>
我需要每次显示值
League:
无论如何,如果该值未绑定,我看不到任何联盟:在gui上,如何解决此问题?请确保ViewModel或Bind属性返回null或空字符串,或使用单独的标签您可以使用适当的ContentTemplate:
<Label Content="{Binding MatchController.Match.Competition}">
<Label.ContentTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="League: "/>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</Label.ContentTemplate>
</Label>
或更短,设置绑定的回退值:
<Label Content="{Binding MatchController.Match.Competition, FallbackValue=''}"
ContentStringFormat="League: {0}">
我知道,我唯一不欣赏wpf的地方是太多的代码无法实现简单的目标