WPF:有没有办法在不重新定义整个样式的情况下覆盖 ControlTemplate 的一部分? [英] WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?

查看:19
本文介绍了WPF:有没有办法在不重新定义整个样式的情况下覆盖 ControlTemplate 的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 WPF xctk:ColorPicker 的样式.我想更改下拉视图和文本的背景颜色 重新定义整个样式.

I am trying to style a WPF xctk:ColorPicker. I want to change the background color of the dropdown view and text without redefining the whole style.

我知道 ColorPicker 包含例如一个名为PART_ColorPickerPalettePopup"的部分.有没有一种方法可以以我的风格直接引用这部分,例如提供一种新的背景颜色?

I know that the ColorPicker contains e.g. a part named "PART_ColorPickerPalettePopup". Is there a way that I can directly reference this part in my style, providing e.g. a new Background color only?

我想避免重新定义PART_ColorPickerPalettePopup"的所有其他属性.

I want to avoid having to redefine all the other properties of "PART_ColorPickerPalettePopup".

链接到我正在描述的 ColorPicker

推荐答案

你可以将一个 Style 建立在另一个 Style 的基础上并覆盖特定的 setter:

You can base a Style on another Style and override specfic setters:

<Style x:Key="myStyle" TargetType="xctk:ColorPicker" BasedOn="{StaticResource {x:Type xctk:ColorPicker}}">
    <!-- This will override the Background setter of the base style -->
    <Setter Property="Background" Value="Red" />
</Style>

但是您不能覆盖"仅 ControlTemplate 的一部分.不幸的是,您必须(重新)将整个模板定义为一个整体.

But you cannot "override" only a part of a ControlTemplate. Unfortunately you must then (re)define the entire template as a whole.

这篇关于WPF:有没有办法在不重新定义整个样式的情况下覆盖 ControlTemplate 的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆