benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.7k stars 143 forks source link

How to use StyleTriggers with Adonis? #157

Closed Morasiu closed 2 years ago

Morasiu commented 3 years ago

Hello

I have a simple button like this.

image

But when I apply some style Trigger it breaks!

image

It's white icon on white background

My code:

<Button Name="PauseButton" Margin="10 0 0 0" MaxHeight="15" MaxWidth="30"
                      Grid.Column="9" Grid.Row="0" Padding="3">
                <Image Source="Assets\play.png" />
                <Button.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsIgnored}" Value="True">
                                <Setter Property="Button.IsEnabled" Value="False" />
                            </DataTrigger>
                    </Style>
                </Button.Style>
        </Button>

NOTE: I have a default setup for Dark theme on Adonis

How can I properly use Adonis with Style Triggers?

benruehl commented 2 years ago

By setting a style like this your are throwing away Adonis UI's default style and the system fallback gets used instead. In order to add to Adonis UI's default style you need to base your style on it:

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

For further information see for example this stackoverflow thread.

On a personal note, it seems that you only want to set the button's IsEnabled property. This can be achieved without creating a style much easier:

<Button IsEnabled="{Binding IsIgnored, Converter={StaticResource InverseBooleanConverter}}"/>

You can create the converter on your own or use one of many libraries that offer those. See this stackoverflow thread or make use of NKristek.Wpf.Converters or Kent.Boogaart.Converters for example.