forked from microsoft/microsoft-ui-xaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainPage.xaml.cs
259 lines (230 loc) · 8.79 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Globalization;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Common;
#if USING_TAEF
using WEX.TestExecution;
using WEX.TestExecution.Markup;
using WEX.Logging.Interop;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
#endif
namespace MUXControlsTestApp
{
public sealed partial class MainPage : Page
{
List<string> locales = new List<string>
{
"af-ZA",
"am-ET",
"ar-SA",
"az-Latn-AZ",
"be-BY",
"bg-BG",
"bn-BD",
"bs-Latn-BA",
"ca-ES",
"cs-CZ",
"da-DK",
"de-DE",
"el-GR",
"en-GB",
"en-US",
"es-ES",
"es-MX",
"et-EE",
"eu-ES",
"fa-IR",
"fi-FI",
"fil-PH",
"fr-CA",
"fr-FR",
"gl-ES",
"ha-Latn-NG",
"he-IL",
"hi-IN",
"hr-HR",
"hu-HU",
"id-ID",
"is-IS",
"it-IT",
"ja-JP",
"ka-GE",
"kk-KZ",
"km-KH",
"kn-IN",
"ko-KR",
"lo-LA",
"lt-LT",
"lv-LV",
"mk-MK",
"ml-IN",
"ms-MY",
"nb-NO",
"nl-NL",
"nn-NO",
"pl-PL",
"pt-BR",
"pt-PT",
"ro-RO",
"ru-RU",
"sk-SK",
"sl-SI",
"sq-AL",
"sr-Latn-RS",
"sv-SE",
"sw-KE",
"ta-IN",
"te-IN",
"th-TH",
"tr-TR",
"uk-UA",
"uz-Latn-UZ",
"vi-VN",
"zh-CN",
"zh-TW"
};
public List<FlowDirection> FlowDirections
{
get;
} = new List<FlowDirection>() { FlowDirection.LeftToRight, FlowDirection.RightToLeft };
public List<Tuple<ApplicationHighContrastAdjustment, string>> AppHighContrastAdjustments
{
get;
} = new List<Tuple<ApplicationHighContrastAdjustment, string>> {
new Tuple<ApplicationHighContrastAdjustment, string>(ApplicationHighContrastAdjustment.None, "None (high-contrast aware)"),
new Tuple<ApplicationHighContrastAdjustment, string>(ApplicationHighContrastAdjustment.Auto, "Auto (unaware)") };
public MainPage()
{
this.InitializeComponent();
AutomationProperties.SetName(this, "MainPage");
Loaded += OnLoaded;
foreach (var locale in locales)
{
var item = new ComboBoxItem { Content = locale };
LanguageChooser.Items.Add(item);
AutomationProperties.SetAutomationId(item, locale);
}
foreach (var flowDirection in FlowDirections)
{
var item = new ComboBoxItem { Content = flowDirection.ToString(), Tag = flowDirection };
FlowDirectionChooser.Items.Add(item);
AutomationProperties.SetAutomationId(item, flowDirection.ToString());
}
foreach (var adjustment in AppHighContrastAdjustments)
{
var item = new ComboBoxItem { Content = adjustment.Item2, Tag = adjustment.Item1 };
AppHighContrastAdjustmentChooser.Items.Add(item);
AutomationProperties.SetAutomationId(item, (string)item.Content);
}
// This setting is persisted across multiple openings of an app, so we always want to initialize it to en-US
// in case the app crashed while in a different language or otherwise was not able to set it back.
MUXControlsTestApp.App.LanguageOverride = "en-US";
// We'll additionally make sure that the combo box begins on the right element to reflect the current value.
LanguageChooser.SelectedIndex = locales.IndexOf("en-US");
LongAnimationsDisabled.IsChecked = MUXControlsTestApp.App.DisableLongAnimations;
FlowDirectionChooser.SelectedIndex = FlowDirections.IndexOf(GetRootFlowDirection());
AppHighContrastAdjustmentChooser.SelectedIndex = AppHighContrastAdjustments.FindIndex(a => a.Item1 == ApplicationHighContrastAdjustment.None); // default to aware
// App remembers ExtendViewIntoTitleBar and the value persists true if test case aborted and didn't change it back
// Always set it to false when app restarted
CoreApplicationViewTitleBar titleBar = CoreApplication.GetCurrentView().TitleBar;
titleBar.ExtendViewIntoTitleBar = false;
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new FrameworkElementAutomationPeer(this);
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
var automationPeer = new FrameworkElementAutomationPeer(this);
automationPeer.RaiseAutomationEvent(AutomationEvents.AsyncContentLoaded);
}
public List<TestDeclaration> Tests
{
get { return TestInventory.Tests; }
}
DependencyObject SearchVisualTree(DependencyObject root, string name)
{
int size = VisualTreeHelper.GetChildrenCount(root);
DependencyObject child = null;
for (int i = 0; i < size && child == null; i++)
{
DependencyObject depObj = VisualTreeHelper.GetChild(root, i);
FrameworkElement fe = depObj as FrameworkElement;
if (fe.Name.Equals(name))
{
child = fe;
}
else
{
child = SearchVisualTree(fe, name);
}
}
return child;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// This method gets called when we navigate to MainPage.
// Now we should unload the scroller dictionary!
App.RemoveResourceDictionaryFromMergedDictionaries(App.AdditionStylesXaml);
LanguageChooser.SelectedItem = MUXControlsTestApp.App.LanguageOverride;
var testContentLoadedCheckBox = SearchVisualTree(this.Frame, "TestContentLoadedCheckBox") as CheckBox;
if (testContentLoadedCheckBox != null)
{
testContentLoadedCheckBox.IsChecked = false;
}
else
{
Log.Warning("Warning: Couldn't find the TestContentLoadedCheckBox to uncheck in OnNavigatedTo");
}
}
private void LanguageChooser_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MUXControlsTestApp.App.LanguageOverride = (string)((ComboBoxItem)LanguageChooser.SelectedItem).Content;
}
private void LongAnimationsDisabled_Checked(object sender, RoutedEventArgs e)
{
MUXControlsTestApp.App.DisableLongAnimations = true;
}
private void LongAnimationsDisabled_Unchecked(object sender, RoutedEventArgs e)
{
MUXControlsTestApp.App.DisableLongAnimations = false;
}
private void FlowDirectionChooser_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
FrameworkElement root = Window.Current.Content as FrameworkElement;
if (root != null)
{
root.FlowDirection = (FlowDirection)((ComboBoxItem)FlowDirectionChooser.SelectedItem).Tag;
}
}
private void AppHighContrastAdjustmentChooser_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
App.Current.HighContrastAdjustment = (ApplicationHighContrastAdjustment)((ComboBoxItem)AppHighContrastAdjustmentChooser.SelectedItem).Tag;
}
private FlowDirection GetRootFlowDirection()
{
return (Window.Current.Content as FrameworkElement)?.FlowDirection ?? FlowDirection.LeftToRight;
}
}
}