-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on ThemeManager.Current.DetectTheme #3779
Comments
The version of MahApps.Metro supporting the current ThemeManager implementation from ControlzEx is not released to nuget yet. |
I will add protective code to the theme detection in ControlzEx to not treat "old" dictionaries as current themes. |
MahApps 2.0.0-alpha0821 containes now latest ControlzEx 4.3.0-alpha0107 |
I just updated to 2.0.0 stable release but the issue seems to still be there, any advice? |
@Luk164 If I use the above sample https://github.com/mauricio-bv/MahappsIssue and update to the latest stable then I can't reproduce the error. Can you look which ControlzEx version your are using? It should be the v4.3.0. |
@punker76 It seems there were some more significant changes. I am using windows template studio and this class seems to be broken by the update. Broken classFilename is ThemeSelectorService.cs. using System;
using System.Windows;
using Archivator_desktop_WPF_WTS.Contracts.Services;
using Archivator_desktop_WPF_WTS.Models;
using MahApps.Metro;
using Microsoft.Win32;
namespace Archivator_desktop_WPF_WTS.Services
{
public class ThemeSelectorService : IThemeSelectorService
{
//private bool IsHighContrastActive => SystemParameters.HighContrast;
public ThemeSelectorService()
{
SystemEvents.UserPreferenceChanging += OnUserPreferenceChanging;
}
public bool SetTheme(AppTheme? theme = null)
{
//if (IsHighContrastActive)
//{
// // TO DO: Set high contrast theme name
//}
//else
if (theme == null)
{
if (App.Current.Properties.Contains("Theme"))
{
// Saved theme
var themeName = App.Current.Properties["Theme"].ToString();
theme = (AppTheme)Enum.Parse(typeof(AppTheme), themeName);
}
else
{
// Default theme
theme = AppTheme.Light;
}
}
var currentTheme = ThemeManager.DetectTheme(Application.Current);
if (currentTheme == null || currentTheme.Name != theme.ToString())
{
ThemeManager.ChangeTheme(Application.Current, $"{theme}.Blue");
App.Current.Properties["Theme"] = theme.ToString();
return true;
}
return false;
}
public AppTheme GetCurrentTheme()
{
var themeName = App.Current.Properties["Theme"]?.ToString();
Enum.TryParse(themeName, out AppTheme theme);
return theme;
}
private void OnUserPreferenceChanging(object sender, UserPreferenceChangingEventArgs e)
{
if (e.Category == UserPreferenceCategory.Color ||
e.Category == UserPreferenceCategory.VisualStyle)
{
SetTheme();
}
}
}
} |
Ok I managed to fix it by downloading the latest tamplate and comparing changes. Thats what I get for using a tool in beta I guess... |
When running the following line:
ControlzEx.Theming.ThemeManager.Current.DetectTheme(Application.Current.MainWindow);
I get the Following error:
See a simple example in my GitHub repo"
https://github.com/mauricio-bv/MahappsIssue.git
Screenshots
![image](https://user-images.githubusercontent.com/6034616/80269668-c27a8780-867f-11ea-865c-a3b1dabdb0f8.png)
Environment:
Additional context
This does not happen when running from the source code (latest commit in Git)
The text was updated successfully, but these errors were encountered: