public Boolean SetCurrentTheme(String name, Boolean applySetting)
        {
            try
            {
                // Find theme for name
                IMesTheme theme = Themes.FirstOrDefault(x => x.Name == name);
                if (theme == null)
                {
                    return(false);
                }
                CurrentTheme = theme;

                // Setup asnc info
                Mvx.IoCProvider.Resolve <IMvxMainThreadAsyncDispatcher>()
                .ExecuteOnMainThreadAsync(() =>
                {
                    // Setup app style
                    ResourceDictionary appTheme =
                        Application.Current.Resources.MergedDictionaries.Count > 0
                        ? Application.Current.Resources.MergedDictionaries[0] : null;

                    if (appTheme == null)
                    {
                        appTheme = new ResourceDictionary();
                        Application.Current.Resources.MergedDictionaries.Add(appTheme);
                    }

                    appTheme.BeginInit();

                    appTheme.MergedDictionaries.Clear();
                    foreach (Uri uri in theme.ApplicationResources)
                    {
                        ResourceDictionary newDict = new ResourceDictionary {
                            Source = uri
                        };
                        appTheme.MergedDictionaries.Add(newDict);
                    }
                    appTheme.EndInit();
                });

                _log.Info($"Theme set to {name}");

                // publish event
                _messenger.Publish(new MesThemeChangeMessage(this, CurrentTheme.Name));

                if (applySetting)
                {
                    Properties.Settings.Default.ThemeName = CurrentTheme.Name;
                }

                return(true);
            } catch (Exception e)
            {
                _log.InfoException("Log Theme Setting", e);
                return(false);
            }
        }
Beispiel #2
0
 public static void Info(this IMvxLog logger, Exception exception, string message, params object[] args)
 {
     logger.InfoException(message, exception, args);
 }