Gauthier
Gauthier

Reputation: 1331

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.

Upvotes: 3

Views: 3466

Answers (1)

Rekshino
Rekshino

Reputation: 7325

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>

Upvotes: 3

Related Questions