-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.xaml.cs
67 lines (57 loc) · 2.15 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Linq;
using System.Windows;
using Localization.WPF;
using StyledWindow.WPF.Commands;
using TestApp.WPF.Properties;
namespace TestApp.WPF
{
public partial class App
{
public App()
{
//ThemeEx.ChangeCulture += Action<string>;
SetCulture();
}
protected override async void OnStartup(StartupEventArgs e)
{
await ThemeEx.LoadThemeAsync(null);
//var load_com = new LoadThemeCommand();
//load_com.Execute(null);
base.OnStartup(e);
}
protected override async void OnExit(ExitEventArgs e)
{
await ThemeEx.SaveThemeAsync(null).ConfigureAwait(true);
//var save_com = new SaveThemeCommand();
//save_com.Execute(null);
base.OnExit(e);
}
/// <summary>Set current culture settings</summary>
private static void SetCulture()
{
ThemeEx.ChangeCulture += LocalizationManager.ChangeCulture;
LocalizationManager.CultureChanging += (s, e) => //Running when application culture is changed
{
var culture = e.NewCulture;
TestApp.WPF.Properties.Resources.Culture = culture;
//Insert other projects or libraries here
};
LocalizationManager.CultureChanged += (s, e) =>
{
//Here we save the settings that will be applied when the application starts
Settings.Default.Culture = e.NewCulture.Name;
Settings.Default.Save();
};
//Here we load the settings that was saved at last time
var settings = Settings.Default;
var last_culture = settings.Culture;
var new_culture = last_culture == string.Empty ? "ru-RU" : last_culture;
//or was sent in command line arguments
var args = Environment.GetCommandLineArgs();
if (args.Contains("-en")) new_culture = "en-US";
else if (args.Contains("-rus")) new_culture = "ru-RU";
LocalizationManager.ChangeCulture(new_culture);
}
}
}