Exemplo n.º 1
0
 private static void internalChangeTheme(SharedResourceDictionary CustomDictionary)
 {
     if (Enumerable.Count<ResourceDictionary>((IEnumerable<ResourceDictionary>)System.Windows.Application.Current.Resources.MergedDictionaries) > 0)
         (System.Windows.Application.Current.Resources.MergedDictionaries[0] as SharedResourceDictionary).ClearShared();
     System.Windows.Application.Current.Resources.MergedDictionaries.Clear();
     if (CustomDictionary != null)
         System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)CustomDictionary);
     else if (SettingsData.Instance.Accent == "Custom")
     {
         switch (SettingsData.Instance.AccentColour)
         {
             case ColourAccent.DarkBlue:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/DarkBlue.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Blue:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Blue.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Purple:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Purple.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Pink:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Pink.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Red:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Red.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Orange:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Orange.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Green:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Green.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Lime:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Lime.xaml", UriKind.Absolute)
                 });
                 break;
             case ColourAccent.Silver:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Silver.xaml", UriKind.Absolute)
                 });
                 break;
             default:
                 System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
                 {
                     Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/Blue.xaml", UriKind.Absolute)
                 });
                 break;
         }
     }
     else
         System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
         {
             Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Accents/DarkBlue.xaml", UriKind.Absolute)
         });
     switch (string.IsNullOrEmpty(SettingsData.Instance.Theme) ? "Dark" : SettingsData.Instance.Theme)
     {
         case "Dark":
             System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
             {
                 Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Dark.xaml", UriKind.Absolute)
             });
             break;
         case "Light":
             System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
             {
                 Source = new Uri("pack://application:,,,/FlattyTweet.Themes;component/Light.xaml", UriKind.Absolute)
             });
             break;
        
     }
     StreamReader streamReader = new StreamReader(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/FlattyTweet.Themes;component/Shared/Theme.txt", UriKind.Absolute)).Stream);
     string str;
     while ((str = streamReader.ReadLine()) != null)
         System.Windows.Application.Current.Resources.MergedDictionaries.Add((ResourceDictionary)new SharedResourceDictionary()
         {
             Source = new Uri(string.Format("pack://application:,,,/FlattyTweet.Themes;component/Shared/{0}", (object)str), UriKind.Absolute)
         });
     streamReader.Close();
     Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)ViewModelMessages.ThemeChanged);
     DispatcherTimer dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render, System.Windows.Application.Current.Dispatcher);
     dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000.0);
     dispatcherTimer.Tick += (EventHandler)((s, a) =>
     {
         Messenger.Default.Send<GenericMessage<object>>(new GenericMessage<object>((object)null), (object)ViewModelMessages.ThemeChangeUI);
         (s as DispatcherTimer).Stop();
     });
     dispatcherTimer.Start();
     GC.Collect();
 }
Exemplo n.º 2
0
 public static void ChangeTheme(SharedResourceDictionary CustomDictionary = null)
 {
     if (System.Windows.Application.Current.MainWindow != null && System.Windows.Application.Current.MainWindow.IsLoaded)
     {
         Messenger.Default.Send<DialogMessage>(new DialogMessage(string.Empty, (Action<MessageBoxResult>)(o => { })), (object)DialogType.ThemeChange);
         DispatcherTimer dispatcherTimer = new DispatcherTimer(DispatcherPriority.Render, System.Windows.Application.Current.Dispatcher);
         dispatcherTimer.Interval = TimeSpan.FromMilliseconds(250.0);
         dispatcherTimer.Tick += (EventHandler)((s, a) =>
         {
             (s as DispatcherTimer).Stop();
             CommonCommands.internalChangeTheme(CustomDictionary);
         });
         dispatcherTimer.Start();
     }
     else
         CommonCommands.internalChangeTheme(CustomDictionary);
 }