Siegfried.V
Siegfried.V

Reputation: 1595

Button default style not applied if Triggers added

I defined a default style for all my application Buttons in App.xaml :

<Style TargetType="{x:Type Button}">
    <Setter Property="FontSize" Value="14"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border 
                    x:Name="Border"  
                    CornerRadius="2" 
                    BorderThickness="1"
                    Background="{StaticResource WindowBorderColor}"
                    BorderBrush="{StaticResource WindowBorderColor}">
                    <ContentPresenter Margin="2" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="{StaticResource InactiveBackgroundColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource InactiveForegroundColor}"/>
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Background" Value="{StaticResource HeaderButtonOverColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource HeaderForeHighlightColor}"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Background" Value="{StaticResource HeaderButtonPressedColor}"/>
                        <Setter Property="Foreground" Value="{StaticResource WindowForeColor}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

But when I want to add a Trigger to my Button, the default style is not taken in account anymore :

<Button Content="{x:Static p:Resources.Delete}" Click="DeleteMacro_Click" Margin="3" >
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding MacroLeft.Name, Mode=OneWay}" Value="">
                    <Setter Property="Button.IsEnabled" Value="False" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

I found that link, so I added TargetType="{x:Type Button}" in my WPF, but nothing changed. Why is the default style not taken in account, and how can I solve that, without creating another specific style in my app.xaml?

Upvotes: 1

Views: 87

Answers (1)

AJITH
AJITH

Reputation: 1175

You can make the styles defined in app.xaml as base in the following way

<Button.Style>
     <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">

     </Style>
</Button.Style>

Upvotes: 3

Related Questions