【发布时间】:2012-06-06 16:00:11
【问题描述】:
我有一个为内容控件定义模板的样式。
对于所有内容属性为空的控件,我想显示文本说控件为空...但是下面的 xaml 不起作用,有人知道为什么吗?
<Style TargetType="ContentControl" x:Key="style">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Content, RelativeSource={RelativeSource Self}}" Value="{x:Null}">
<Setter Property="ContentControl.Template">
<Setter.Value>
<ControlTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Background="Blue">EMPTY!</TextBlock>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
<ContentControl Content="{x:Null}" Style="{StaticResource style}" />
它没有显示文本“EMPTY!”。
【问题讨论】:
标签: wpf xaml data-binding wpf-controls