'How can I change a MahApps.Metro progress bar color, based on the current theme?
I have a MahApps.Metro progress bar defined like this;
<Controls:MetroProgressBar Name="progressBar"
Grid.Column="0"
Grid.Row="2"
Minimum="0"
Maximum="100"
Height="20"
Foreground="LightBlue"
/>
Instead of having the Foreground defined as a static LightBlue, I'd like to have it change based on my current theme.
I'm changing the themes using their ThemeManager
MahApps.Metro.ThemeManager.ChangeAppStyle(System.Windows.Application.Current,
MahApps.Metro.ThemeManager.GetAccent(myAccent),
MahApps.Metro.ThemeManager.GetAppTheme(myTheme));
Is there a way to get whatever the current Theme or Accent is from the application and into the xaml file?
Solution 1:[1]
Bonus answer: Here is how you change it with a binding to a bool in the DataContext. It reverts back to the default when the bound property is false
<Controls:MetroProgressBar.Style>
<Style TargetType="Controls:MetroProgressBar">
<Setter Property="Foreground" Value="{DynamicResource AccentColorBrush}" />
<Style.Triggers>
<DataTrigger Binding="{Binding PublicBoolInDataContext}"
Value="True">
<Setter Property="Foreground" Value="DarkRed" />
</DataTrigger>
</Style.Triggers>
</Style>
</Controls:MetroProgressBar.Style>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | CAD bloke |
