-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
155 lines (134 loc) · 5.08 KB
/
Copy pathMainPage.xaml.cs
File metadata and controls
155 lines (134 loc) · 5.08 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
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
using Windows.UI.ViewManagement;
using WinUI.TableView.SampleApp.Helpers;
using WinUI.TableView.SampleApp.Pages;
namespace WinUI.TableView.SampleApp;
public sealed partial class MainPage : Page
{
private readonly DispatcherQueue _dispatcherQueue;
private readonly UISettings _settings = new();
private bool _canNavigate = true;
public MainPage()
{
InitializeComponent();
App.Current.MainWindow.Activated += OnMainWindowActivated;
App.Current.MainWindow.SetTitleBar(AppTitleBar);
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
_settings.ColorValuesChanged += delegate { OnSettingsColorValuesChanged(); };
}
private async void OnPageLoaded(object sender, RoutedEventArgs e)
{
OnSettingsColorValuesChanged();
await ExampleViewModel.InitializeItemsAsync();
SetLoading(false);
#if DEBUG
navigationView.SelectedItem = navigationView.MenuItems[2];
#else
navigationView.SelectedItem = overViewNavItem;
#endif
}
internal void SetLoading(bool isLoading)
{
loadingIndicator.Visibility = isLoading ? Visibility.Visible : Visibility.Collapsed;
}
private void OnMainWindowActivated(object sender, WindowActivatedEventArgs args)
{
#if WINDOWS
if (args.WindowActivationState == WindowActivationState.Deactivated)
{
VisualStateManager.GoToState(this, "Deactivated", true);
}
else
{
VisualStateManager.GoToState(this, "Activated", true);
}
#endif
}
private void OnPaneDisplayModeChanged(NavigationView sender, NavigationViewDisplayModeChangedEventArgs args)
{
if (sender.PaneDisplayMode == NavigationViewPaneDisplayMode.Top)
{
VisualStateManager.GoToState(this, "Top", true);
}
else
{
if (args.DisplayMode == NavigationViewDisplayMode.Minimal)
{
VisualStateManager.GoToState(this, "Compact", true);
}
else
{
VisualStateManager.GoToState(this, "Default", true);
}
}
}
// this handles updating the caption button colors correctly when windows system theme is changed
// while the app is open
private void OnSettingsColorValuesChanged()
{
// This calls comes off-thread, hence we will need to dispatch it to current app's thread
_dispatcherQueue.TryEnqueue(() => TitleBarHelper.ApplySystemThemeToCaptionButtons(App.Current.MainWindow));
}
private void OnNavigationSelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if (!_canNavigate)
{
return;
}
if (args.SelectedItem is NavigationViewItem { Content: string } selectedItem)
{
var pageType = selectedItem.Content.ToString() switch
{
"Settings" => typeof(SettingsPage),
"Overview" => typeof(OverviewPage),
"Grid Lines" => typeof(GridLinesPage),
"Selection" => typeof(SelectionPage),
"Corner Button" => typeof(CornerButtonPage),
"Alternate Row Color" => typeof(AlternateRowColorPage),
"Context Flyouts" => typeof(ContextFlyoutsPage),
"Row Reorder" => typeof(ReorderRowsPage),
"Pagination" => typeof(PaginationPage),
"Filtering" => typeof(FilteringPage),
"Customize Filter Flyout" => typeof(CustomizeFilterPage),
"External Filtering" => typeof(ExternalFilteringPage),
"Clipboard Actions" => typeof(ClipboardActionsPage),
"Editing" => typeof(EditingPage),
"Sorting" => typeof(SortingPage),
"Custom Sorting" => typeof(CustomizeSortingPage),
"Data Export" => typeof(ExportPage),
"Large Dataset" => typeof(LargeDataPage),
"Conditional Cell Styling" => typeof(ConditionalStylingPage),
_ => typeof(BlankPage)
};
rootFrame.Navigate(pageType, selectedItem);
}
}
private void OnBackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
{
if (rootFrame.CanGoBack)
{
rootFrame.GoBack();
}
}
private async void OnRootFrameNavigated(object sender, NavigationEventArgs e)
{
_canNavigate = false;
if (e.NavigationMode == NavigationMode.Back && e.Parameter is NavigationViewItem navItem && !navItem.Equals(navigationView.SelectedItem))
{
navigationView.SelectedItem = navItem;
}
if (e.Content is Page page)
{
page.NavigationCacheMode = NavigationCacheMode.Disabled;
if (page.DataContext is null)
{
await Task.Delay(10);
page.DataContext = new ExampleViewModel();
}
}
_canNavigate = true;
}
}