Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the foreground color of all command buttons in MahApps

Is there a way to change buttons foreground in MetroWindow? I have even tried to override the IronicallyNamedChromelessButtonStyle but the foreground color was still the same.

Edit: The buttons are in the Window Bar (e.g Close, Minimize, Maximize).

like image 411
user3049133 Avatar asked Feb 05 '14 12:02

user3049133


1 Answers

After a deep dive into the MahApps codе... Here is the source which is responsible for the buttons: https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/Themes/MetroWindow.xaml If you look carefully, you will notice that every style has triggers that override the style foreground with hard-coded "White":

<Style.Triggers>
        <DataTrigger Binding="{Binding ShowTitleBar, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
                     Value="True">
            <Setter Property="Foreground"
                    Value="White" />
        </DataTrigger>
        <DataTrigger Binding="{Binding ShowTitleBar, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
                     Value="False">
            <Setter Property="Background"
                    Value="Transparent" />
        </DataTrigger>
    </Style.Triggers>

My solution was to override all necessary style triggers:

<Style TargetType="{x:Type MahControls:WindowButtonCommands}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding ShowTitleBar, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type MahControls:MetroWindow}}}"
                     Value="True">
            <Setter Property="Foreground"
                    Value="{StaticResource IdealForegroundColorBrush}" />
        </DataTrigger>
    </Style.Triggers>
</Style>

Hope this will help anyone in my case. Special thanks to @Rui and @Sankarann for the ideas and help. If anyone have a better solution, please share it.

like image 129
user3049133 Avatar answered Oct 20 '22 16:10

user3049133