更改 WPF 中 ResizeGrip 的颜色

Chn*_*sos 2 c# wpf xaml

我想更改ResizeGrip's 方块的颜色,但找不到正确的属性。

我尝试覆盖默认的 ResizeGrip 样式如下:

<Style TargetType="{x:Type ResizeGrip}">
    <Setter Property="Foreground" Value="{StaticResource WindowBackground}" />
</Style>
Run Code Online (Sandbox Code Playgroud)

我认为 ControlTemplate 太复杂了,无法从 TemplatedParent 访问该属性。

那么,我应该覆盖 ControlTemplate 吗?通过代码掌握?或者我错过了什么更容易的东西?

Chr*_* W. 5

如果我们去检查默认模板,我们会看到这些属性不仅没有模板绑定,而且在那里有一个硬设置“透明”。所以我们可以填补空缺;

编辑

<Style x:Key="blah" TargetType="{x:Type ResizeGrip}">
   <Setter Property="OverridesDefaultStyle" Value="True" />
   <Setter Property="Foreground" Value="Blue"/>
   <Setter Property="Background" Value="Transparent"/>
   <Setter Property="Template">
      <Setter.Value>
         <ControlTemplate TargetType="{x:Type ResizeGrip}">
            <Border Background="{TemplateBinding Background}"
                    SnapsToDevicePixels="True"
                    Width="10"
                    Height="10">
                <Path Data="M7.677,7.5300003 L9.677,7.5300003 9.677,9.5300002 7.677,9.5300002 z M3.786,7.5300003 L5.7859998,7.5300003 5.7859998,9.5300002 3.786,9.5300002 z M0,7.5300003 L2,7.5300003 2,9.5300002 0,9.5300002 z M3.786,3.8280003 L5.7859998,3.8280003 5.7859998,5.8280003 3.786,5.8280003 z M7.677,3.7660003 L9.677,3.7660003 9.677,5.7659999 7.677,5.7659999 z M7.677,0 L9.677,0 9.677,2 7.677,2 z" Fill="{TemplateBinding Foreground}" Height="9.53" Stretch="Fill" VerticalAlignment="Top" Width="9.677"/>
             </Border>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

现在你可以随心所欲了;

<ResizeGrip Foreground="Red" Style="{StaticResource blah}"/>
Run Code Online (Sandbox Code Playgroud)

希望这有帮助,干杯。