Reputation: 2270
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?
Upvotes: 2
Views: 5574
Reputation: 8798
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>
Upvotes: 1
Reputation: 623
The current themes' accent color is defined in resource AccentColor
as a Color and in resource AccentColorBrush
as a Brush. You can simply assign the Brush to your progressbar:
<Controls:MetroProgressBar Name="progressBar"
Grid.Column="0"
Grid.Row="2"
Minimum="0"
Maximum="100"
Height="20"
Foreground="{DynamicResource AccentColorBrush}"
/>
Upvotes: 3