why ButtonPressedBackgroundThemeBrush is not working for button

38 Views Asked by At

Whenever I press and hold the button I can see a blue color background till I release the button

I tried to reset it white by using the key ButtonPressedBackgroundThemeBrush

Here is my button code

                <Button Content="Submit" BorderThickness="0"  HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" FontSize="21"  Height="85" BorderBrush="White" Command="{Binding testCommand}" Foreground="{StaticResource Green}">
                    <Button.Resources>
                        <SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White" />
                    </Button.Resources>
                </Button>

But its not working for some reason.

1

There are 1 best solutions below

1
Matt L. On

Try defining the brush in your application resources:

<Application.Resources>
    <SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White" />
</Application.Resources>

This will change the button press background for ALL buttons however. If you want specific buttons to have different backgrounds, you'll need to edit the Button template for each. One simple way to do that is to define a style for each and set the Background to whatever you like during the IsPressed Trigger

<Button>
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <Trigger Property="IsPressed" Value="True">
                    <Setter Property="Background" Value="White"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>