我有一个定义内容控件模板的样式。
对于所有内容属性为 null 的控件,我想显示说明该控件为空的文本...但是下面的 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!”。
最佳答案
你的代码可以工作。把你的 GUI 设计器扔到窗外。
关于wpf - 数据触发器绑定(bind)未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10917842/