private void ChangeTheme(object sender, RoutedEventArgs e) { this.currentAccent = ThemeManager.DefaultAccents.First(x => x.Name == "Green"); ThemeManager.ChangeTheme(App.Current, this.currentAccent, this.currentTheme); ThemeManager.ChangeTheme(this, this.currentAccent, this.currentTheme); //ThemeManager.ChangeTheme((ResourceDictionary)this.FindResource("CurrentAccent"), this.currentAccent, Theme.Light); }
public void ChangeAccent(Accent accent) { var theme = MahApps.Metro.ThemeManager.DetectAppStyle(Application.Current); MahApps.Metro.ThemeManager.ChangeAppStyle(Application.Current, accent, theme.Item1); CurrentConfiguration.Accent = accent.Name; Task.Run(() => Save()); }
public static void ChangeTheme(ResourceDictionary r, Accent accent, Theme theme) { ThemeIsDark = (theme == Theme.Dark); var themeResource = (theme == Theme.Light) ? LightResource : DarkResource; ApplyResourceDictionary(themeResource, r); ApplyResourceDictionary(accent.Resources, r); }
public static void ChangeTheme(Application app, Accent newAccent, Theme newTheme) { if (app == null) throw new ArgumentNullException("app"); var oldTheme = DetectTheme(app); ChangeTheme(app.Resources, oldTheme, newAccent, newTheme); }
private static void OnThemeChanged(Accent newAccent, AppTheme newTheme) { SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs() { AppTheme = newTheme, Accent = newAccent }); }
internal static bool GetThemeFromResources(AppTheme presetTheme, ResourceDictionary dict, ref Tuple <AppTheme, Accent> detectedAccentTheme) { bool flag; AppTheme appTheme = presetTheme; Accent accent = ThemeManager.GetAccent(dict); Accent accent1 = accent; if (accent != null) { detectedAccentTheme = Tuple.Create <AppTheme, Accent>(appTheme, accent1); return(true); } using (IEnumerator <ResourceDictionary> enumerator = dict.MergedDictionaries.GetEnumerator()) { while (enumerator.MoveNext()) { if (!ThemeManager.GetThemeFromResources(presetTheme, enumerator.Current, ref detectedAccentTheme)) { continue; } flag = true; return(flag); } return(false); } return(flag); }
public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme) { if (window == null) throw new ArgumentNullException("window"); var oldTheme = DetectTheme(window); ChangeTheme(window.Resources, oldTheme, newAccent, newTheme); }
/// <summary> /// </summary> public void Load() { if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Accent)) { _styleAccent = ThemeManager.GetAccent(Properties.Settings.Default.Accent); } if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.Theme)) { _styleTheme = ThemeManager.GetAppTheme(Properties.Settings.Default.Theme); } _mainWindow.Accent.SelectedValue = _styleAccent.Name; switch (_styleTheme.Name) { case "BaseDark": _mainWindow.Dark.IsChecked = true; _mainWindow.Light.IsChecked = false; break; case "BaseLight": _mainWindow.Dark.IsChecked = false; _mainWindow.Light.IsChecked = true; break; } SetStyle(); foreach (var accent in ThemeManager.Accents) { _mainWindow.Accent.Items.Add(accent.Name); } }
private void SkinButton_Click(object sender, RoutedEventArgs e) { Int32 i = random.Next(0,21); currentAccent = ThemeManager.DefaultAccents.First(x => x.Name == accentAll[i]); ThemeManager.ChangeTheme(Application.Current, currentAccent, currentTheme); Application.Current.Properties["currentAccent"] = accentAll[i]; }
public static void ChangeTheme(ResourceDictionary r, Accent newAccent, Theme newTheme) { var themeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; ApplyResourceDictionary(newAccent.Resources, r); ApplyResourceDictionary(themeResource, r); }
public MainWindow() { InitializeComponent(); Client.ExecutingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //Set up logging before we do anything AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; if (File.Exists(Path.Combine(Client.ExecutingDirectory, "lcdebug.log"))) { File.Delete(Path.Combine(Client.ExecutingDirectory, "lcdebug.log")); } AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException; if (File.Exists(Path.Combine(Client.ExecutingDirectory, "lcdebug.log"))) { File.Delete(Path.Combine(Client.ExecutingDirectory, "lcdebug.log")); } Client.InfoLabel = InfoLabel; Client.StartHeartbeat(); Client.PVPNet = new PVPNetConnection(); Client.PVPNet.KeepDelegatesOnLogout = false; Client.PVPNet.OnError += Client.PVPNet_OnError; Steel = new Accent("Steel", new Uri("pack://application:,,,/LegendaryClient;component/Controls/Steel.xaml")); if (Properties.Settings.Default.DarkTheme) { ThemeManager.ChangeTheme(this, Steel, Theme.Dark); } Client.ChatClient = new JabberClient(); ChatContainer.Content = new ChatPage().Content; StatusContainer.Content = new StatusPage().Content; NotificationOverlayContainer.Content = new FakePage().Content; NotificationContainer.Content = new NotificationsPage().Content; Grid NotificationTempGrid = null; foreach (var x in NotificationOverlayContainer.GetChildObjects()) { if (x is Grid) { NotificationTempGrid = x as Grid; } } Client.PlayButton = PlayButton; Client.Pages = new List<Page>(); Client.MainGrid = MainGrid; Client.NotificationGrid = NotificationTempGrid; Client.MainWin = this; Client.Container = Container; Client.OverlayContainer = OverlayContainer; Client.ChatContainer = ChatContainer; Client.StatusContainer = StatusContainer; Client.NotificationContainer = NotificationContainer; Client.NotificationOverlayContainer = NotificationOverlayContainer; Client.SwitchPage(new PatcherPage()); }
public App() : base() { Messenger.Default.Register<BalloonToolTipMessage>(this, HandleToolTipMessage); //load possible assemblies var n = new GoToMessage(); var a = new Accent(); DispatcherUnhandledException += OnDispatcherUnhandledException; }
protected TenCentMailWindow() { var accent = new Accent("TenCentMail", new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/TenCentMail.xaml")); ThemeManager.ChangeTheme(this, accent, Theme.Light); WindowStartupLocation = WindowStartupLocation.CenterOwner; Width = 516; Loaded += (sender, e) => MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); SetBinding(DialogCloser.DialogResultProperty, new Binding("DialogResult")); }
public static void CreateAppStyleBy(Color color, bool changeImmediately = false) { // create a runtime accent resource dictionary var resourceDictionary = new ResourceDictionary(); resourceDictionary.Add("HighlightColor", color); resourceDictionary.Add("AccentColor", Color.FromArgb((byte)(204), color.R, color.G, color.B)); resourceDictionary.Add("AccentColor2", Color.FromArgb((byte)(153), color.R, color.G, color.B)); resourceDictionary.Add("AccentColor3", Color.FromArgb((byte)(102), color.R, color.G, color.B)); resourceDictionary.Add("AccentColor4", Color.FromArgb((byte)(51), color.R, color.G, color.B)); resourceDictionary.Add("HighlightBrush", new SolidColorBrush((Color)resourceDictionary["HighlightColor"])); resourceDictionary.Add("AccentColorBrush", new SolidColorBrush((Color)resourceDictionary["AccentColor"])); resourceDictionary.Add("AccentColorBrush2", new SolidColorBrush((Color)resourceDictionary["AccentColor2"])); resourceDictionary.Add("AccentColorBrush3", new SolidColorBrush((Color)resourceDictionary["AccentColor3"])); resourceDictionary.Add("AccentColorBrush4", new SolidColorBrush((Color)resourceDictionary["AccentColor4"])); resourceDictionary.Add("WindowTitleColorBrush", new SolidColorBrush((Color)resourceDictionary["AccentColor"])); resourceDictionary.Add("ProgressBrush", new LinearGradientBrush( new GradientStopCollection(new[] { new GradientStop((Color)resourceDictionary["HighlightColor"], 0), new GradientStop((Color)resourceDictionary["AccentColor3"], 1) }), new Point(0.001, 0.5), new Point(1.002, 0.5))); resourceDictionary.Add("CheckmarkFill", new SolidColorBrush((Color)resourceDictionary["AccentColor"])); resourceDictionary.Add("RightArrowFill", new SolidColorBrush((Color)resourceDictionary["AccentColor"])); resourceDictionary.Add("IdealForegroundColor", Colors.White); resourceDictionary.Add("IdealForegroundColorBrush", new SolidColorBrush((Color)resourceDictionary["IdealForegroundColor"])); resourceDictionary.Add("AccentSelectedColorBrush", new SolidColorBrush((Color)resourceDictionary["IdealForegroundColor"])); // applying theme to MahApps var resDictName = string.Format("ApplicationAccent_{0}.xaml", color.ToString().Replace("#", string.Empty)); var fileName = Path.Combine(Path.GetTempPath(), resDictName); using (var writer = System.Xml.XmlWriter.Create(fileName, new System.Xml.XmlWriterSettings { Indent = true })) { System.Windows.Markup.XamlWriter.Save(resourceDictionary, writer); writer.Close(); } resourceDictionary = new ResourceDictionary() { Source = new Uri(fileName, UriKind.Absolute) }; var newAccent = new Accent { Name = resDictName, Resources = resourceDictionary }; ThemeManager.AddAccent(newAccent.Name, newAccent.Resources.Source); if (changeImmediately) { var application = Application.Current; var applicationTheme = ThemeManager.AppThemes.First(x => string.Equals(x.Name, "BaseLight")); ThemeManager.ChangeAppStyle(application, newAccent, applicationTheme); } }
public static void ChangeAppStyle(Application app, Accent newAccent, AppTheme newTheme) { if (app == null) { throw new ArgumentNullException("app"); } Tuple <AppTheme, Accent> tuple = ThemeManager.DetectAppStyle(app); ThemeManager.ChangeAppStyle(app.Resources, tuple, newAccent, newTheme); }
public static void ChangeAppStyle(ResourceDictionary resources, Accent newAccent, AppTheme newTheme) { if (resources == null) { throw new ArgumentNullException("resources"); } ApplyResourceDictionary(newAccent.Resources, resources); ApplyResourceDictionary(newTheme.Resources, resources); }
public static void ChangeAppStyle(Window window, Accent newAccent, AppTheme newTheme) { if (window == null) { throw new ArgumentNullException("window"); } Tuple <AppTheme, Accent> tuple = ThemeManager.DetectAppStyle(window); ThemeManager.ChangeAppStyle(window.Resources, tuple, newAccent, newTheme); }
public static void ChangeAppStyle(Application app, Accent newAccent, AppTheme newTheme) { if (app == null) { throw new ArgumentNullException("app"); } var oldTheme = DetectAppStyle(app); ChangeAppStyle(app.Resources, oldTheme, newAccent, newTheme); }
public static void ChangeAppStyle(Window window, Accent newAccent, AppTheme newTheme) { if (window == null) { throw new ArgumentNullException("window"); } var oldTheme = DetectAppStyle(window); ChangeAppStyle(window.Resources, oldTheme, newAccent, newTheme); }
public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme) { if (resources == null) { throw new ArgumentNullException("resources"); } AppTheme appTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]); ChangeAppStyle(resources, newAccent, appTheme); }
public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme) { if (resources == null) { throw new ArgumentNullException("resources"); } var themeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; ApplyResourceDictionary(newAccent.Resources, resources); ApplyResourceDictionary(themeResource, resources); }
/// <summary> /// Sets the theme color of the application. This method dynamically creates an in-memory resource /// dictionary containing the accent colors used by MahApps. /// </summary> public static void ApplyTheme() { //<Color x:Key="HighlightColor"> // #800080 //</Color> //<Color x:Key="AccentColor"> // #CC800080 //</Color> //<Color x:Key="AccentColor2"> // #99800080 //</Color> //<Color x:Key="AccentColor3"> // #66800080 //</Color> //<Color x:Key="AccentColor4"> // #33800080 //</Color> //<SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource HighlightColor}" /> //<SolidColorBrush x:Key="AccentColorBrush" Color="{StaticResource AccentColor}" /> //<SolidColorBrush x:Key="AccentColorBrush2" Color="{StaticResource AccentColor2}" /> //<SolidColorBrush x:Key="AccentColorBrush3" Color="{StaticResource AccentColor3}" /> //<SolidColorBrush x:Key="AccentColorBrush4" Color="{StaticResource AccentColor4}" /> //<SolidColorBrush x:Key="WindowTitleColorBrush" Color="{StaticResource AccentColor}" /> //<SolidColorBrush x:Key="AccentSelectedColorBrush" Color="White" /> //<LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5"> // <GradientStop Color="{StaticResource HighlightColor}" Offset="0" /> // <GradientStop Color="{StaticResource AccentColor3}" Offset="1" /> //</LinearGradientBrush> //<SolidColorBrush x:Key="CheckmarkFill" Color="{StaticResource AccentColor}" /> //<SolidColorBrush x:Key="RightArrowFill" Color="{StaticResource AccentColor}" /> //<Color x:Key="IdealForegroundColor"> // Black //</Color> //<SolidColorBrush x:Key="IdealForegroundColorBrush" Color="{StaticResource IdealForegroundColor}" /> // Theme is always the 0-index of the resources var application = Application.Current; var applicationResources = application.Resources; var resourceDictionary = applicationResources.MergedDictionaries[0]; var applicationTheme = ThemeManager.AppThemes.First(x => string.Equals(x.Name, "BaseLight")); // Insert to get the best MahApps performance (when looking up themes) applicationResources.MergedDictionaries.Insert(1, applicationTheme.Resources); Log.Debug("Applying theme to MahApps"); var newAccent = new Accent { Resources = resourceDictionary }; ThemeManager.ChangeAppStyle(application, newAccent, applicationTheme); }
public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme) { if (window == null) { throw new ArgumentNullException("window"); } var oldTheme = DetectTheme(window); AppTheme oldAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[oldTheme.Item1]); AppTheme newAppTheme = AppThemes.First(x => x.Name == reverseCompatibilityThemeMapping[newTheme]); ChangeAppStyle(window.Resources, Tuple.Create(oldAppTheme, oldTheme.Item2), newAccent, newAppTheme); }
public static MetroRadiance.UI.Accent FromMahAccent(MahApps.Metro.Accent accent) { try { return(MetroRadiance.UI.Accent.GetAccentFromString(accent.Name)); } catch /* if metroRadiance hasn't provided accent by mahApp's, then marApp's accent convert to metroRadiance color; */ { var colorList = ThemeManager.Accents.Select(a => new { a.Name, Brush = a.Resources["AccentColorBrush"] as Brush }); var selectedColor = colorList.FirstOrDefault(r => r.Name == accent.Name).Brush; var color = ((SolidColorBrush)selectedColor).Color; return(MetroRadiance.UI.Accent.FromColor(color)); } }
private Accent SetTheme(Accent t) { Accent c = currTheme; if (currTheme != t) { currTheme = t; Application.Current.Dispatcher.Invoke(() => { var themestr = (repository.LatestManifest != null && repository.LatestManifest.darkTheme) ? "BaseDark" : "BaseLight"; ThemeManager.ChangeAppStyle(Application.Current, t, ThemeManager.GetAppTheme(themestr)); }); } return c; }
private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme) { bool flag = false; if (oldThemeInfo == null) { ThemeManager.ChangeAppStyle(resources, newAccent, newTheme); flag = true; } else { Accent item2 = oldThemeInfo.Item2; if (item2 != null && item2.Name != newAccent.Name) { string lower = item2.Resources.Source.ToString().ToLower(); ResourceDictionary resourceDictionaries = ( from x in resources.MergedDictionaries where x.Source != null select x).FirstOrDefault <ResourceDictionary>((ResourceDictionary d) => d.Source.ToString().ToLower() == lower); if (resourceDictionaries != null) { resources.MergedDictionaries.Add(newAccent.Resources); resources.MergedDictionaries.Remove(resourceDictionaries); flag = true; } } AppTheme item1 = oldThemeInfo.Item1; if (item1 != null && item1 != newTheme) { string str = item1.Resources.Source.ToString().ToLower(); ResourceDictionary resourceDictionaries1 = ( from x in resources.MergedDictionaries where x.Source != null select x).FirstOrDefault <ResourceDictionary>((ResourceDictionary d) => d.Source.ToString().ToLower() == str); if (resourceDictionaries1 != null) { resources.MergedDictionaries.Add(newTheme.Resources); resources.MergedDictionaries.Remove(resourceDictionaries1); flag = true; } } } if (flag) { ThemeManager.OnThemeChanged(newAccent, newTheme); } }
private static void ChangeTheme(ResourceDictionary resources, Tuple<Theme, Accent> oldThemeInfo, Accent accent, Theme newTheme) { if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Item2; if (oldAccent != null && oldAccent.Name != accent.Name) { var accentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source); if (accentResource != null) { var ok = resources.MergedDictionaries.Remove(accentResource); // really need this??? foreach (DictionaryEntry r in accentResource) { if (resources.Contains(r.Key)) resources.Remove(r.Key); } resources.MergedDictionaries.Add(accent.Resources); } } var oldTheme = oldThemeInfo.Item1; if (oldTheme != null && oldTheme != newTheme) { var oldThemeResource = (oldTheme == Theme.Light) ? LightResource : DarkResource; var md = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldThemeResource.Source); if (md != null) { var ok = resources.MergedDictionaries.Remove(md); var newThemeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; // really need this??? foreach (DictionaryEntry r in oldThemeResource) { if (resources.Contains(r.Key)) resources.Remove(r.Key); } resources.MergedDictionaries.Add(newThemeResource); } } } else { ChangeTheme(resources, accent, newTheme); } }
private static void ChangeTheme(ResourceDictionary resources, Tuple<Theme, Accent> oldThemeInfo, Accent newAccent, Theme newTheme) { var themeChanged = false; if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Item2; if (oldAccent != null && oldAccent.Name != newAccent.Name) { var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source); if (oldAccentResource != null) { resources.MergedDictionaries.Add(newAccent.Resources); var ok = resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true; } } var oldTheme = oldThemeInfo.Item1; if (oldTheme != null && oldTheme != newTheme) { var oldThemeResource = (oldTheme == Theme.Light) ? LightResource : DarkResource; var md = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldThemeResource.Source); if (md != null) { var newThemeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; resources.MergedDictionaries.Add(newThemeResource); var ok = resources.MergedDictionaries.Remove(md); themeChanged = true; } } } else { ChangeTheme(resources, newAccent, newTheme); themeChanged = true; } if (themeChanged) { OnThemeChanged(newAccent, newTheme); } }
public static void ChangeAppStyle([NotNull] Window window, [NotNull] Accent newAccent, [NotNull] AppTheme newTheme) { if (window == null) { throw new ArgumentNullException(nameof(window)); } if (newAccent == null) { throw new ArgumentNullException(nameof(newAccent)); } if (newTheme == null) { throw new ArgumentNullException(nameof(newTheme)); } var oldTheme = DetectAppStyle(window); ChangeAppStyle(window.Resources, oldTheme, newAccent, newTheme); }
public static void ChangeAppStyle([NotNull] Application app, [NotNull] Accent newAccent, [NotNull] AppTheme newTheme) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (newAccent == null) { throw new ArgumentNullException(nameof(newAccent)); } if (newTheme == null) { throw new ArgumentNullException(nameof(newTheme)); } var oldTheme = DetectAppStyle(app); ChangeAppStyle(app.Resources, oldTheme, newAccent, newTheme); }
private static void OnThemeChanged(Accent newAccent, Theme newTheme) { SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs() { Theme = newTheme, Accent = newAccent }); var invalidateColors = typeof(SystemColors).GetMethod("InvalidateCache", BindingFlags.Static | BindingFlags.NonPublic); if (invalidateColors != null) { invalidateColors.Invoke(null, null); } var invalidateParameters = typeof(SystemParameters).GetMethod("InvalidateCache", BindingFlags.Static | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (invalidateParameters != null) { invalidateParameters.Invoke(null, null); } var assembly = Assembly.GetAssembly(typeof(Window)); if (assembly != null) { var systemResources = assembly.GetType("System.Windows.SystemResources"); if (systemResources != null) { var onThemeChanged = systemResources.GetMethod("OnThemeChanged", BindingFlags.Static | BindingFlags.NonPublic); if (onThemeChanged != null) { onThemeChanged.Invoke(null, null); } var invalidateResources = systemResources.GetMethod("InvalidateResources", BindingFlags.Static | BindingFlags.NonPublic); if (invalidateResources != null) { invalidateResources.Invoke(null, new object[] { false }); } } } }
public MainWindow() { InitializeComponent(); Client.ExecutingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); Client.InfoLabel = InfoLabel; Client.PVPNet = new PVPNetConnection(); Client.PVPNet.KeepDelegatesOnLogout = false; Client.PVPNet.OnError += Client.PVPNet_OnError; Steel = new Accent("Steel", new Uri("pack://application:,,,/LegendaryClient;component/Controls/Steel.xaml")); if (Properties.Settings.Default.DarkTheme) { ThemeManager.ChangeTheme(this, Steel, Theme.Dark); } Client.ChatClient = new JabberClient(); ChatContainer.Content = new ChatPage().Content; StatusContainer.Content = new StatusPage().Content; NotificationOverlayContainer.Content = new FakePage().Content; Grid NotificationTempGrid = null; foreach (var x in NotificationOverlayContainer.GetChildObjects()) { if (x is Grid) { NotificationTempGrid = x as Grid; } } Client.PlayButton = PlayButton; Client.Pages = new List<Page>(); Client.MainGrid = MainGrid; Client.NotificationGrid = NotificationTempGrid; Client.MainWin = this; Client.Container = Container; Client.OverlayContainer = OverlayContainer; Client.ChatContainer = ChatContainer; Client.StatusContainer = StatusContainer; Client.NotificationOverlayContainer = NotificationOverlayContainer; Client.SwitchPage(new PatcherPage()); }
private static void OnThemeChanged(Accent newAccent, Theme newTheme) { SafeRaise.Raise(IsThemeChanged, Application.Current, new OnThemeChangedEventArgs() { Theme = newTheme, Accent = newAccent }); Action apply = () => { if (SystemColors_InvalidateColors != null) { SystemColors_InvalidateColors.Invoke(null, null); } // See: https://github.com/MahApps/MahApps.Metro/issues/923 //var invalidateParameters = typeof(SystemParameters).GetMethod("InvalidateCache", BindingFlags.Static | BindingFlags.NonPublic, null, Type.EmptyTypes, null); //if (invalidateParameters != null) //{ // invalidateParameters.Invoke(null, null); //} if (SystemResources_OnThemeChanged != null) { SystemResources_OnThemeChanged.Invoke(null, null); } if (SystemResources_InvalidateResources != null) { SystemResources_InvalidateResources.Invoke(null, new object[] { false }); } }; if (InvalidateSystemResourcesOnBackgroundThread) { Task.Factory.StartNew(apply); } else { apply(); } }
internal static bool GetThemeFromResources(AppTheme presetTheme, ResourceDictionary dict, ref Tuple <AppTheme, Accent> detectedAccentTheme) { AppTheme currentTheme = presetTheme; Accent matched = null; if ((matched = GetAccent(dict)) != null) { detectedAccentTheme = Tuple.Create <AppTheme, Accent>(currentTheme, matched); return(true); } foreach (ResourceDictionary rd in dict.MergedDictionaries) { if (GetThemeFromResources(presetTheme, rd, ref detectedAccentTheme)) { return(true); } } return(false); }
public static Accent GetAccent(ResourceDictionary resources) { if (resources == null) { throw new ArgumentNullException("resources"); } Accent accent = ThemeManager.Accents.FirstOrDefault <Accent>((Accent x) => ThemeManager.AreResourceDictionarySourcesEqual(x.Resources.Source, resources.Source)); if (accent != null) { return(accent); } if (!(resources.Source == null) || !ThemeManager.IsAccentDictionary(resources)) { return(null); } return(new Accent() { Name = "Runtime accent", Resources = resources }); }
internal static bool GetThemeFromResources(Theme presetTheme, ResourceDictionary dict, ref Tuple <Theme, Accent> detectedAccentTheme) { Theme currentTheme = presetTheme; Accent currentAccent = null; Accent matched = null; if ((matched = ((List <Accent>)DefaultAccents).Find(x => x.Resources.Source == dict.Source)) != null) { currentAccent = matched; detectedAccentTheme = Tuple.Create <Theme, Accent>(currentTheme, currentAccent); return(true); } foreach (ResourceDictionary rd in dict.MergedDictionaries) { if (GetThemeFromResources(presetTheme, rd, ref detectedAccentTheme)) { return(true); } } return(false); }
/// <summary> /// Creates a new instance of this class. /// </summary> public OnThemeChangedEventArgs(AppTheme appTheme, Accent accent) { this.AppTheme = appTheme; this.Accent = accent; }
public void InitializeThemeObject() { Light = ThemeManager.GetAppTheme("BaseLight"); CurrentAccent = ThemeManager.GetAccent("Blue"); }
private void ColorChange(object sender, RoutedEventArgs e) { Button selectedButton = (Button)sender; String selectedColor = selectedButton.Name.ToString(); Console.WriteLine(selectedColor); CurrentAccent = ThemeManager.GetAccent(selectedColor); ThemeManager.ChangeAppStyle(Application.Current, CurrentAccent, Light); }
public static void ChangeTheme(Window window, Accent newAccent, Theme newTheme) { var oldTheme = DetectTheme(window); ChangeTheme(window.Resources, oldTheme, newAccent, newTheme); }
private void InitializeGui() { ReturnToPage.Visibility = Visibility.Hidden; Client.UserTitleBarLabel = UserTitleBarLabel; Client.UserTitleBarImage = UserTitleBarImage; Client.InfoLabel = InfoLabel; if (string.IsNullOrEmpty(Settings.Default.Theme)) Settings.Default.Theme = "pack://application:,,,/LegendaryClient;component/Controls/Steel.xaml"; _myAccent = new Accent("AccentName", new Uri(Settings.Default.Theme)); ThemeManager.ChangeAppStyle(this, _myAccent, (Settings.Default.DarkTheme) ? ThemeManager.GetAppTheme("BaseDark") : ThemeManager.GetAppTheme("BaseLight")); ChatContainer.Content = Client.FriendList.Content; Client.notificationPage = new NotificationPage(); NotificationContainer.Content = Client.notificationPage.Content; Client.statusPage = new StatusPage(); StatusContainer.Content = Client.statusPage.Content; NotificationOverlayContainer.Content = new Grid(); Grid notificationTempGrid = null; foreach (var x in NotificationOverlayContainer.GetChildObjects().OfType<Grid>()) notificationTempGrid = x; ChangeTheme(); Client.FullNotificationOverlayContainer = FullNotificationOverlayContainer; Client.PlayButton = PlayButton; Client.Pages = new List<Page>(); Client.MainGrid = MainGrid; Client.BackgroundImage = BackImage; Client.NotificationGrid = notificationTempGrid; Client.MainWin = this; Client.Container = Container; Client.OverlayContainer = OverlayContainer; Client.OverOverlayContainer = OverOverlayContainer; Client.NotificationContainer = NotificationContainer; Client.ChatContainer = ChatContainer; Client.StatusContainer = StatusContainer; Client.ReturnButton = ReturnToPage; Client.inQueueTimer = inQueueTimer; Client.NotificationOverlayContainer = NotificationOverlayContainer; Client.SoundPlayer = SoundPlayer; Client.AmbientSoundPlayer = ASoundPlayer; Client.SwitchPage(new PatcherPage()); if (!string.IsNullOrEmpty(Settings.Default.LoginPageImage) && Settings.Default.UseAsBackgroundImage) { if (File.Exists(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Settings.Default.LoginPageImage.Replace("\r\n", "")))) Client.BackgroundImage.Source = new BitmapImage(new Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "champions", Settings.Default.LoginPageImage), UriKind.Absolute)); } // screen resolution fix: because MainWindow height is bigger than some screen height if (SystemParameters.WorkArea.Height < Height) { // resize LC to MinHeight -- a UI designer may edit this SizeToContent = SizeToContent.Manual; Width = MinWidth; MinHeight = Height; } }
public static void ChangeTheme(Window window, Accent accent, Theme theme) { ChangeTheme(window.Resources, accent, theme); }
private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme) { var themeChanged = false; if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Item2; if (oldAccent != null && oldAccent.Name != newAccent.Name) { var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source); if (oldAccentResource != null) { resources.MergedDictionaries.Add(newAccent.Resources); var ok = resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true; } } var oldTheme = oldThemeInfo.Item1; if (oldTheme != null && oldTheme != newTheme) { var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldTheme.Resources.Source); if (oldThemeResource != null) { resources.MergedDictionaries.Add(newTheme.Resources); var ok = resources.MergedDictionaries.Remove(oldThemeResource); themeChanged = true; } } } else { ChangeAppStyle(resources, newAccent, newTheme); themeChanged = true; } if (themeChanged) { OnThemeChanged(newAccent, newTheme); } }
/// <summary> /// change accent and theme for the given window /// </summary> public static void ChangeTheme(Window window, Accent accent, Theme theme) { var oldTheme = DetectTheme(window); ChangeTheme(window.Resources, oldTheme, accent, theme); }
private static void ChangeAppStyle(ResourceDictionary resources, Tuple <AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme) { var themeChanged = false; if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Element2; if (oldAccent != null && oldAccent.Name != newAccent.Name) { var key = oldAccent.Resources.Source.ToString().ToLower(); var oldAccentResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key); if (oldAccentResource != null) { resources.MergedDictionaries.Add(newAccent.Resources); resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true; } } var oldTheme = oldThemeInfo.Element1; if (oldTheme != null && oldTheme != newTheme) { var key = oldTheme.Resources.Source.ToString().ToLower(); var oldThemeResource = resources.MergedDictionaries.Where(x => x.Source != null).FirstOrDefault(d => d.Source.ToString().ToLower() == key); if (oldThemeResource != null) { resources.MergedDictionaries.Add(newTheme.Resources); resources.MergedDictionaries.Remove(oldThemeResource); themeChanged = true; } } } else { ChangeAppStyle(resources, newAccent, newTheme); themeChanged = true; } if (themeChanged) { OnThemeChanged(newAccent, newTheme); } }
private static void ChangeTheme(ResourceDictionary resources, Tuple <Theme, Accent> oldThemeInfo, Accent newAccent, Theme newTheme) { var themeChanged = false; if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Item2; if (oldAccent != null && oldAccent.Name != newAccent.Name) { var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source); if (oldAccentResource != null) { resources.MergedDictionaries.Add(newAccent.Resources); var ok = resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true; } } var oldTheme = oldThemeInfo.Item1; if (oldTheme != null && oldTheme != newTheme) { var oldThemeResource = (oldTheme == Theme.Light) ? LightResource : DarkResource; var md = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldThemeResource.Source); if (md != null) { var newThemeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; resources.MergedDictionaries.Add(newThemeResource); var ok = resources.MergedDictionaries.Remove(md); themeChanged = true; } } } else { ChangeTheme(resources, newAccent, newTheme); themeChanged = true; } if (themeChanged) { OnThemeChanged(newAccent, newTheme); } }
public static void ChangeTheme(Application app, Accent newAccent, Theme newTheme) { var oldTheme = DetectTheme(app); ChangeTheme(app.Resources, oldTheme, newAccent, newTheme); }
private static void ChangeAppStyle(ResourceDictionary resources, Tuple<AppTheme, Accent> oldThemeInfo, Accent newAccent, AppTheme newTheme) { var themeChanged = false; if (oldThemeInfo != null) { var oldAccent = oldThemeInfo.Item2; if (oldAccent != null && oldAccent.Name != newAccent.Name) { var oldAccentResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldAccent.Resources.Source); if (oldAccentResource != null) { resources.MergedDictionaries.Add(newAccent.Resources); var ok = resources.MergedDictionaries.Remove(oldAccentResource); themeChanged = true; } } var oldTheme = oldThemeInfo.Item1; if (oldTheme != null && oldTheme != newTheme) { var oldThemeResource = resources.MergedDictionaries.FirstOrDefault(d => d.Source == oldTheme.Resources.Source); if (oldThemeResource != null) { resources.MergedDictionaries.Add(newTheme.Resources); var ok = resources.MergedDictionaries.Remove(oldThemeResource); themeChanged = true; } } } else { ChangeAppStyle(resources, newAccent, newTheme); themeChanged = true; } if (themeChanged) { OnThemeChanged(newAccent, newTheme); } }
private static void OnThemeChanged(Accent newAccent, AppTheme newTheme) { IsThemeChanged?.Invoke(Application.Current, new OnThemeChangedEventArgs(newTheme, newAccent)); }
public static void ChangeAppStyle(ResourceDictionary resources, Accent newAccent, AppTheme newTheme) { if (resources == null) throw new ArgumentNullException("resources"); ApplyResourceDictionary(newAccent.Resources, resources); ApplyResourceDictionary(newTheme.Resources, resources); }
/// <summary> /// change accent and theme for the hole application /// </summary> public static void ChangeTheme(Application app, Accent accent, Theme theme) { var oldTheme = DetectTheme(app); ChangeTheme(app.Resources, oldTheme, accent, theme); }
public void ChangeTheme() { var myAccent = new Accent("AccentName", new Uri(Settings.Default.Theme)); ThemeManager.ChangeAppStyle(Application.Current, myAccent, (Settings.Default.DarkTheme) ? ThemeManager.GetAppTheme("BaseDark") : ThemeManager.GetAppTheme("BaseLight")); var random = new Random().Next(-9000, 9000); myAccent = new Accent(random.ToString(), new Uri(Settings.Default.Theme)); ThemeManager.ChangeAppStyle(Application.Current, myAccent, (Settings.Default.DarkTheme) ? ThemeManager.GetAppTheme("BaseDark") : ThemeManager.GetAppTheme("BaseLight")); Client.CurrentAccent = myAccent; }
public static void ChangeTheme(Application app, Accent accent, Theme theme) { ChangeTheme(app.Resources, accent, theme); }
public static void ChangeTheme(ResourceDictionary resources, Accent newAccent, Theme newTheme) { if (resources == null) throw new ArgumentNullException("resources"); var themeResource = (newTheme == Theme.Light) ? LightResource : DarkResource; ApplyResourceDictionary(newAccent.Resources, resources); ApplyResourceDictionary(themeResource, resources); }
private void ChangeAccent(string accentName) { this.currentAccent = ThemeManager.DefaultAccents.First(x => x.Name == accentName); ThemeManager.ChangeTheme(this, this.currentAccent, this.currentTheme); }
public AccentViewModel(Accent accent) { Accent = accent; }
private void GreenButtonClick(object sender, RoutedEventArgs e) { currentAccent = ThemeManager.DefaultAccents.First(x => x.Name == "Green"); ThemeManager.ChangeTheme(Application.Current, currentAccent, currentTheme); }