Last Updated: February 25, 2016
·
292
· 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}">
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="Control.IsMouseOver" Value="true"></Condition>
                <Condition Property="Button.IsPressed" Value="false"></Condition>
            </MultiTrigger.Conditions>
    <Setter Property="Control.Background" Value="{DynamicResource DangerColorBrush}"></Setter>
        </MultiTrigger>
    </Style.Triggers>
</Style>

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