【发布时间】:2023-03-14 14:04:02
【问题描述】:
我有一个属性HashCodeValue。基于 HashCodeValue 属性中的 HashCode,我需要使用 DataTrigger 更改控件的可见性。
WPF XAML 源代码:
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="DummyFilterDataGridColumnHeader">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Button Content="Super I" Visibility="Collapsed" />
<Button Content="Super II" Visibility="Collapsed" />
<Button Content="Super III" Visibility="Collapsed" />
<ControlTemplate.Triggers>
<DataTrigger Property="{Binding HashCodeValue}" Value="???">
<Setter TargetName="Button" Property="Visibility" Value="Visible" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我们无法在编译时知道 HashCode,它仅在运行时生成。在三个按钮中,该属性在运行时保存任何一个按钮的 HashCode。根据值,我想将对应按钮的Visibility改为Visible。
请帮助我如何为我的场景编写 DataTrigger。
【问题讨论】:
标签: c# wpf hashcode controltemplate datatrigger