This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainPage.xaml.cs
118 lines (111 loc) · 3.63 KB
/
MainPage.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Diagnostics;
using Translate.Pages;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Translate
{
public sealed partial class MainPage : Page
{
internal IPropertySet settings = Windows.Storage.ApplicationData.Current.LocalSettings.Values;
public MainPage()
{
this.InitializeComponent();
CreateDataFile();
var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
coreTitleBar.ExtendViewIntoTitleBar = true;
Window.Current.SetTitleBar(DragRegion);
UpdateSettings(null);
}
private async void CreateDataFile()
{
if ((await ApplicationData.Current.LocalFolder.GetFilesAsync()).Count == 0)
{
await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("data.json");
}
else
{
}
}
private void UpdateSettings(string setting)
{
if (setting == null)
{
UpdateSettings("compactmode");
UpdateSettings("history");
}
else if (settings?.ContainsKey(setting) == true && (settings[setting]?.ToString() == "True" || settings[setting]?.ToString() == "False"))
{
bool value = StringToBool(settings[setting].ToString());
if (setting == "compactmode")
{
int height;
if (value)
{
height = 32;
}
else
{
height = 48;
}
TitleBar.Height = height;
DragRegion.Height = height;
navview.Margin = new Thickness(0, height, 0, 0);
}
if (setting == "history")
{
if (value)
{
HistoryPageButton.Visibility = Visibility.Visible;
}
else
{
HistoryPageButton.Visibility = Visibility.Collapsed;
}
}
}
else
{
}
}
private bool StringToBool(string v)
{
if (v == "True")
{
return true;
}
else
{
return false;
}
}
private void navview_SelectionChanged(Microsoft.UI.Xaml.Controls.NavigationView sender, Microsoft.UI.Xaml.Controls.NavigationViewSelectionChangedEventArgs args)
{
string page = args.SelectedItemContainer.Tag.ToString();
if (args.IsSettingsSelected)
{
contentFrame.Navigate(typeof(SettingsPage));
(contentFrame.Content as SettingsPage).SettingChangedEvent += SettingChanged;
}
else if (page == "History")
{
contentFrame.Navigate(typeof(HistoryPage));
}
else
{
contentFrame.Navigate(typeof(TranslatePage));
}
}
private void SettingChanged(object sender, string setting)
{
UpdateSettings(setting);
}
private void navview_Loaded(object sender, RoutedEventArgs e)
{
(sender as Microsoft.UI.Xaml.Controls.NavigationView).SelectedItem = TranslatePageButton;
}
}
}