I use a custom control from an external library, it has a property with ControlTemplate.
<Style x:Key="{x:Type controls:HeaderDiscountButton}" TargetType="{x:Type controls:HeaderDiscountButton}" BasedOn="{StaticResource {x:Type core:ValueButton}}">
<Setter Property="core:ButtonWithPopup.PopupTemplate">
<Setter.Value>
<ControlTemplate>
some complicated xaml code
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I would like to override it, but use old one in my new ControlTemplate, for example
<Style x:Key="{x:Type controls:HeaderDiscountButton}" TargetType="{x:Type controls:HeaderDiscountButton}" BasedOn="{StaticResource {x:Type core:ValueButton}}">
<Setter Property="core:ButtonWithPopup.PopupTemplate">
<Setter.Value>
<ControlTemplate>
<StackPanel>
<Border>some complicated xaml code</Border>
<Border>some additional xaml code</Border>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I would like to avoid copying whole old code
This is not possible I am afraid. You can indeed base a Style on another Style and override specfic setters but you cannot "override" or inherit only a part of a ControlTemplate. Unfortunately you must (re)define the entire template as a whole.
So in this case you actually need to copy the (whole) original template and then edit it as per your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With