Last Updated: February 25, 2016
· sebastianbusek

Inherit styles in Windows Presentation Fondation

Few moment ago I faced to problem, how to create style which just add some behaviors to existing style.

In my case I just needed create close button. This close button change background color when mouse is over and when button is pressed.

<Style x:Key="WindowCloseButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource WindowButtonStyle}">
                <Condition Property="Control.IsMouseOver" Value="true"></Condition>
                <Condition Property="Button.IsPressed" Value="false"></Condition>
    <Setter Property="Control.Background" Value="{DynamicResource DangerColorBrush}"></Setter>

Important part in this example is BaseOn attribute of style element.