如果属性TextBlock
为空,我想要隐藏Commission.Vehicle.Owner.Name
。代码看起来像这样。当然这不起作用,TextBlock
属性文本将始终为空..
<Style x:Key="CollapsableTextBlock" TargetType="TextBlock">
<Style.Triggers>
<Trigger Property="Text" Value="">
<Setter Property="Visibility" Value="Collapsed"/>
</Trigger>
</Style.Triggers>
</Style>
<TextBlock Style="{DynamicResource CollapsableTextBlock}">
<Run Text="Owner: "/>
<Run Text="{Binding Commission.Vehicle.Owner.Name}"/>
</TextBlock>
任何有想法的人?谢谢!
答案 0 :(得分:6)
DataTrigger应该可以工作:
<Style x:Key="CollapsableTextBlock" TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Commission.Vehicle.Owner.Name}" Value="">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>