Search code examples
c#wpfstylescolor-pickerwpf-extended-toolkit

WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?


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.

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?

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

Link to the ColorPicker I am describing


Solution

  • 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>
    

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