【问题标题】:How to target different type of controls in WPF styles?如何在 WPF 样式中定位不同类型的控件?
【发布时间】:2012-04-16 01:35:54
【问题描述】:

我想为水平和垂直的GridSplitter 设置不同的背景。这是因为我有一个线性渐变,我需要根据网格拆分器的对齐方式将它旋转 90 度。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="{x:Type GridSplitter}">
        <Setter Property="Background" Value="Red" /> <!-- How to get this red applied to only Vertical for instance? -->
    </Style>
</ResourceDictionary>

所以问题是:如何分别针对垂直拆分器和水平拆分器?

【问题讨论】:

    标签: wpf xaml gridsplitter


    【解决方案1】:

    使用Style.Triggers 有条件地应用设置器。

    【讨论】:

      【解决方案2】:

      好的,看来我明白了:

      <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
          <Style TargetType="{x:Type GridSplitter}">
              <Style.Triggers>
                  <Trigger Property="VerticalAlignment" Value="Stretch">
                      <Setter Property="Background" Value="#F7F7F7" />
                  </Trigger>
      
                  <Trigger Property="HorizontalAlignment" Value="Stretch">
                      <Setter Property="Background" Value="red" />
                  </Trigger>
              </Style.Triggers>
          </Style>
      </ResourceDictionary>
      

      【讨论】:

        猜你喜欢
        • 2011-05-07
        • 2015-12-01
        • 1970-01-01
        • 2011-10-17
        • 2023-04-05
        • 2021-05-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多