forked from microsoft/WinUI-Gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsPage.xaml.cs
More file actions
194 lines (174 loc) · 7.13 KB
/
Copy pathSettingsPage.xaml.cs
File metadata and controls
194 lines (174 loc) · 7.13 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************
using System;
using AppUIBasics.Helper;
using Microsoft.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.System;
using WinUIGallery.DesktopWap.Helper;
namespace AppUIBasics
{
/// <summary>
/// A page that displays the app's settings.
/// </summary>
public sealed partial class SettingsPage : Page
{
public string Version
{
get
{
var version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
}
}
public string WinAppSdkRuntimeDetails => App.WinAppSdkRuntimeDetails;
private int lastNavigationSelectionMode = 0;
public SettingsPage()
{
this.InitializeComponent();
Loaded += OnSettingsPageLoaded;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
}
private void OnSettingsPageLoaded(object sender, RoutedEventArgs e)
{
var currentTheme = ThemeHelper.RootTheme;
switch (currentTheme)
{
case ElementTheme.Light:
themeMode.SelectedIndex = 0;
break;
case ElementTheme.Dark:
themeMode.SelectedIndex = 1;
break;
case ElementTheme.Default:
themeMode.SelectedIndex = 2;
break;
}
NavigationRootPage navigationRootPage = NavigationRootPage.GetForElement(this);
if (navigationRootPage != null)
{
if (navigationRootPage.NavigationView.PaneDisplayMode == NavigationViewPaneDisplayMode.Auto)
{
navigationLocation.SelectedIndex = 0;
}
else
{
navigationLocation.SelectedIndex = 1;
}
lastNavigationSelectionMode = navigationLocation.SelectedIndex;
}
if (ElementSoundPlayer.State == ElementSoundPlayerState.On)
soundToggle.IsOn = true;
if (ElementSoundPlayer.SpatialAudioMode == ElementSpatialAudioMode.On)
spatialSoundBox.IsOn = true;
#if DEBUG
ScreenshotCard.Visibility = Visibility.Visible;
#endif
}
private void themeMode_SelectionChanged(object sender, RoutedEventArgs e)
{
var selectedTheme = ((ComboBoxItem)themeMode.SelectedItem)?.Tag?.ToString();
var window = WindowHelper.GetWindowForElement(this);
string color;
if (selectedTheme != null)
{
ThemeHelper.RootTheme = App.GetEnum<ElementTheme>(selectedTheme);
if (selectedTheme == "Dark")
{
TitleBarHelper.SetCaptionButtonColors(window, Colors.White);
color = selectedTheme;
}
else if (selectedTheme == "Light")
{
TitleBarHelper.SetCaptionButtonColors(window, Colors.Black);
color = selectedTheme;
}
else
{
color = TitleBarHelper.ApplySystemThemeToCaptionButtons(window) == Colors.White ? "Dark" : "Light";
}
// announce visual change to automation
UIHelper.AnnounceActionForAccessibility(sender as UIElement, $"Theme changed to {color}",
"ThemeChangedNotificationActivityId");
}
}
private void soundToggle_Toggled(object sender, RoutedEventArgs e)
{
if (soundToggle.IsOn == true)
{
SpatialAudioCard.IsEnabled = true;
ElementSoundPlayer.State = ElementSoundPlayerState.On;
}
else
{
SpatialAudioCard.IsEnabled = false;
spatialSoundBox.IsOn = false;
ElementSoundPlayer.State = ElementSoundPlayerState.Off;
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.Off;
}
}
private void screenshotModeToggle_Toggled(object sender, RoutedEventArgs e)
{
UIHelper.IsScreenshotMode = screenshotModeToggle.IsOn;
}
private void navigationLocation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Since setting the left mode does not look at the old setting we
// need to check if this is an actual update
if (navigationLocation.SelectedIndex != lastNavigationSelectionMode)
{
NavigationOrientationHelper.IsLeftModeForElement(navigationLocation.SelectedIndex == 0, this);
lastNavigationSelectionMode = navigationLocation.SelectedIndex;
}
}
private async void FolderButton_Click(object sender, RoutedEventArgs e)
{
FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
folderPicker.FileTypeFilter.Add(".png"); // meaningless, but you have to have something
StorageFolder folder = await folderPicker.PickSingleFolderAsync();
if (folder != null)
{
UIHelper.ScreenshotStorageFolder = folder;
screenshotFolderLink.Content = UIHelper.ScreenshotStorageFolder.Path;
}
}
private async void screenshotFolderLink_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchFolderAsync(UIHelper.ScreenshotStorageFolder);
}
private void spatialSoundBox_Toggled(object sender, RoutedEventArgs e)
{
if (soundToggle.IsOn == true)
{
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.Off;
}
else
{
ElementSoundPlayer.SpatialAudioMode = ElementSpatialAudioMode.On;
}
}
private void soundPageHyperlink_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(ItemPage), new NavigationRootPageArgs() { Parameter = "Sound", NavigationRootPage = NavigationRootPage.GetForElement(this) });
}
private async void bugRequestCard_Click(object sender, RoutedEventArgs e)
{
await Launcher.LaunchUriAsync(new Uri("https://github.com/microsoft/WinUI-Gallery/issues/new/choose"));
}
}
}