1

I'm using a 3rd party ContentControl which comes with the following theme:

<Style TargetType="{x:Type xyz:XyzControl}" x:Key="XyzControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type xyz:XyzControl}">
                <ControlTemplate.Resources>
                  <Style TargetType="Button">
                     <!-- A lot of styling... -->
                  </Style>
                </ControlTemplate.Resources>
                <!-- More template stuff... -->

I want to add some DataTriggers to buttons inside this control but I want to keep the default styling from the control theme.

<xyz:XyzControl>
  <Button>
    <Button.Style>
      <Style TargetType="Button" BasedOn="{???}">
        <Style.Triggers>
        </Style.Triggers>
      </Style>
    </Button.Style>
  </Button>
</xyz:XyzControl>

I tried to base on {StaticResource {x:Type Button}} but this loads the default global button style, not the default style in this context.

hansmaad
  • 18,417
  • 9
  • 53
  • 94

2 Answers2

0

Add a key to the 3rd party's button style :

<Style TargetType="Button" x:key="xyzbuttonStyle">

then :

<Style TargetType="Button" BasedOn="{StaticResource xyzbuttonStyle}">
Tesseract
  • 180
  • 11
0

This is not possible since you can't base a ControlTemplate on another ControlTemplate. You will have to re-define the entire template as a whole:

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

And adding a trigger to a Style won't affect or "override" the triggers that are defined in the ControlTemplate of the control so you will have to override the entire ControlTemplate from scratch.

You could of course copy the default one into your XAML markup and edit it as per your requirements.

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88