Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Inline style not setting template values

I have some base button styles that i want to inheritand make some minor changes, but not in the main style. I extracted the main problem to a new application with minimal xaml. The only thing i want to accomplish is change the button height when the button is disabled.

The two triggers are what i have tried , neither seem to work or give any debug messages about unable to find what its binding to.

<Button HorizontalAlignment="Center"
    Height="90"
    Margin="5"
    Click="Button_Click"
    VerticalAlignment="Bottom">
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <Trigger Property="Button.IsEnabled"
                         Value="False">
                    <Setter Property="Button.Height"
                            Value="50" />
                </Trigger>
                <DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Self}}"
                             Value="False">
                    <Setter Property="Button.Height"
                            Value="50" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
    Foo Bar
</Button>

The button click

private void Button_Click(object sender, RoutedEventArgs e)
{
    (sender as FrameworkElement).IsEnabled = false;
}

Thanks for reading.

like image 683
Gauthier Avatar asked Dec 08 '25 11:12

Gauthier


1 Answers

Both triggers do work. You set explicitly Height="90" and it overrides your style! If you want it works you should set the initial height in the style and delete it from Button tag.

<Style TargetType="Button">
    <Setter Property="Button.Height" Value="90" />
    <Style.Triggers>
        <Trigger Property="Button.IsEnabled"
                 Value="False">
            <Setter Property="Button.Height"
                    Value="50" />
        </Trigger>
    </Style.Triggers>
</Style>
like image 69
Rekshino Avatar answered Dec 11 '25 01:12

Rekshino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!