Reputation: 5841
I' using mahapps.metro with custom accent. I'm changing accent through code when application starts. Since when I have done that dialogs are not showing up properly.
I couldn't figure out what's going wrong. My App.xaml is,
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Indigo.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="Assets/ButtonStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
and in code,
Uri objUri = new Uri("Assets/CustomAccent.xaml", UriKind.Relative);
Accent acc = new Accent("CustomAccent", objUri);
ThemeManager.ChangeTheme(App.Current, acc, Theme.Light);
In my custom accent, I'm just changing the colors, nothing else. any idea?
Upvotes: 0
Views: 441
Reputation: 14611
To use a custom accent you must add it to the ThemeManager
before you can use it (MahApps.Metro
v1.0.0).
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// add custom accent and theme resource dictionaries
ThemeManager.AddAccent("CustomAccent1", new Uri("pack://application:,,,/MahAppsMetroThemesSample;component/CustomAccents/CustomAccent1.xaml"));
// get the theme from the current application
var theme = ThemeManager.DetectAppStyle(Application.Current);
// now use the custom accent
ThemeManager.ChangeAppStyle(Application.Current,
ThemeManager.GetAccent("CustomAccent1"),
theme.Item1);
base.OnStartup(e);
}
}
Hope this helps.
Upvotes: 1