根据属性值应用样式
在使用 Infragistics XamDataGrid 时,我遇到了一种情况,即我希望仅在设置了某个属性时才应用样式。但是,我认为这更多的是一般性 WPF/样式问题,而不是特定于 xamDataGrid 的问题。
下面的样式是我目前使用的。它将复选框添加到记录选择器区域:
<Style TargetType="{x:Type igDP:RecordSelector}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:RecordSelector}">
<CheckBox x:Name="HeaderCheckBox"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsChecked="{Binding Path=DataItem.IsChecked}">
</CheckBox>
<ControlTemplate.Triggers>
<Trigger Property="IsFilterRecord" Value="True">
<Setter TargetName="HeaderCheckBox" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsAddRecord" Value="True">
<Setter TargetName="HeaderCheckBox" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
TargetType 是 RecordSelector。如果记录是筛选行或添加记录行,我不想显示该复选框。
我想更改此设置,以便如果记录是添加记录行(IsAddRecord == true),则根本不应用该样式。我希望添加记录行保留其默认样式。
这可能吗?
Working with the Infragistics XamDataGrid I encountered a situation where I want a Style applied only if a certain property is set. However, I think this is more of a general WPF/style question than xamDataGrid specific.
The below style is what I am currently using. It adds checkBoxes to the record selector area:
<Style TargetType="{x:Type igDP:RecordSelector}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:RecordSelector}">
<CheckBox x:Name="HeaderCheckBox"
HorizontalAlignment="Center"
VerticalAlignment="Center"
IsChecked="{Binding Path=DataItem.IsChecked}">
</CheckBox>
<ControlTemplate.Triggers>
<Trigger Property="IsFilterRecord" Value="True">
<Setter TargetName="HeaderCheckBox" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsAddRecord" Value="True">
<Setter TargetName="HeaderCheckBox" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
The TargetType is RecordSelector. If the record is either the filter row or the add record row, I don't want to show the check box.
I want to change this so that if the record is the add record row (IsAddRecord == true), then do not apply the style at all. I want the add record row to retain its default style.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法阻止从样式本身应用样式,但可以使用 Style.Triggers 阻止应用其 Setter:
You can't prevent the Style from being aplied from within the Style itself, but you can prevent its Setters from being applied using Style.Triggers: