根据属性值应用样式

发布于 2024-12-03 08:30:41 字数 1433 浏览 3 评论 0原文

在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2024-12-10 08:30:41

您无法阻止从样式本身应用样式,但可以使用 Style.Triggers 阻止应用其 Setter:

<Style TargetType="{x:Type igDP:RecordSelector}">
    <Style.Triggers>
        <Trigger Property="IsAddRecord" Value="False">
            <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>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>

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:

<Style TargetType="{x:Type igDP:RecordSelector}">
    <Style.Triggers>
        <Trigger Property="IsAddRecord" Value="False">
            <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>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Trigger>
    </Style.Triggers>
</Style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文