|
| 1 | +using System; |
| 2 | +using System.Windows; |
| 3 | +using System.Windows.Media; |
| 4 | +using MemPlus.Business.LOG; |
| 5 | +using Syncfusion.Windows.Shared; |
| 6 | + |
| 7 | +namespace MemPlus.Business.GUI |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Static class to change the style of an object |
| 11 | + /// </summary> |
| 12 | + internal static class GuiManager |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Change the visual style of an object |
| 16 | + /// </summary> |
| 17 | + /// <param name="o">The object that needs to have a style overhaul</param> |
| 18 | + internal static void ChangeStyle(DependencyObject o) |
| 19 | + { |
| 20 | + try |
| 21 | + { |
| 22 | + SkinStorage.SetVisualStyle(o, Properties.Settings.Default.VisualStyle); |
| 23 | + SkinStorage.SetMetroBrush(o, new SolidColorBrush(Properties.Settings.Default.MetroColor)); |
| 24 | + if (!(o is ChromelessWindow window)) return; |
| 25 | + window.BorderThickness = new Thickness(Properties.Settings.Default.BorderThickness); |
| 26 | + window.CornerRadius = new CornerRadius(0, 0, 0, 0); |
| 27 | + window.Opacity = Properties.Settings.Default.WindowOpacity; |
| 28 | + window.ResizeBorderThickness = new Thickness(Properties.Settings.Default.WindowResizeBorder); |
| 29 | + } |
| 30 | + catch (Exception ex) |
| 31 | + { |
| 32 | + SkinStorage.SetVisualStyle(o, "Metro"); |
| 33 | + MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Change the language of the application, depending on the settings |
| 39 | + /// </summary> |
| 40 | + /// <param name="logController">The LogController object that can be used to add logs</param> |
| 41 | + internal static void ChangeLanguage(LogController logController) |
| 42 | + { |
| 43 | + logController.AddLog(new ApplicationLog("Changing language")); |
| 44 | + ResourceDictionary dict = new ResourceDictionary(); |
| 45 | + Uri langUri; |
| 46 | + try |
| 47 | + { |
| 48 | + switch (Properties.Settings.Default.SelectedLanguage) |
| 49 | + { |
| 50 | + default: |
| 51 | + langUri = new Uri("..\\Resources\\Languages\\en_US.xaml", UriKind.Relative); |
| 52 | + break; |
| 53 | + case 0: |
| 54 | + langUri = new Uri("..\\Resources\\Languages\\de_DE.xaml", UriKind.Relative); |
| 55 | + break; |
| 56 | + case 2: |
| 57 | + langUri = new Uri("..\\Resources\\Languages\\es_ES.xaml", UriKind.Relative); |
| 58 | + break; |
| 59 | + case 3: |
| 60 | + langUri = new Uri("..\\Resources\\Languages\\fr_FR.xaml", UriKind.Relative); |
| 61 | + break; |
| 62 | + case 4: |
| 63 | + langUri = new Uri("..\\Resources\\Languages\\gl_ES.xaml", UriKind.Relative); |
| 64 | + break; |
| 65 | + case 5: |
| 66 | + langUri = new Uri("..\\Resources\\Languages\\nl_BE.xaml", UriKind.Relative); |
| 67 | + break; |
| 68 | + case 6: |
| 69 | + langUri = new Uri("..\\Resources\\Languages\\nl_NL.xaml", UriKind.Relative); |
| 70 | + break; |
| 71 | + } |
| 72 | + } |
| 73 | + catch (Exception ex) |
| 74 | + { |
| 75 | + langUri = new Uri("..\\Resources\\Languages\\en.xaml", UriKind.Relative); |
| 76 | + logController.AddLog(new ApplicationLog(ex.Message)); |
| 77 | + MessageBox.Show(ex.Message, "MemPlus", MessageBoxButton.OK, MessageBoxImage.Error); |
| 78 | + } |
| 79 | + |
| 80 | + dict.Source = langUri; |
| 81 | + Application.Current.Resources.MergedDictionaries.Clear(); |
| 82 | + Application.Current.Resources.MergedDictionaries.Add(dict); |
| 83 | + |
| 84 | + logController.AddLog(new ApplicationLog("Done changing language")); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments