/
MainPage.xaml.cs
799 lines (703 loc) · 27.5 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Threading.Tasks;
using System.Xml.Linq;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace UnofficialSamsungRemote
{
public sealed partial class MainPage : Page
{
internal static MainPage instance;
internal static Discovery discoverer;
internal static TvConnection directConn;
private bool bFirstLoad = true;
private DateTime inputShown;
public static bool bEnabled { get; private set; }
private const int IanaInterfaceType_Ethernet = 6;
private const int IanaInterfaceType_WiFi = 71;
private Type AboutPageType { get { return typeof(About); } }
private Type SettingsPageType { get { return typeof(UserSettings); } }
private List<NavMenuItem> navlist = new List<NavMenuItem>()
{
new NavMenuItem()
{
Symbol = Symbol.List,
Label = "tv list",
DestPage = typeof(ControllerPages.TvList)
},
new NavMenuItem()
{
Symbol = Symbol.Keyboard,
Label = "numpad",
DestPage = typeof(ControllerPages.Numpad)
},
new NavMenuItem()
{
Symbol = Symbol.Forward,
Label = "navigation",
DestPage = typeof(ControllerPages.Navigation)
},
new NavMenuItem()
{
Symbol = Symbol.Play,
Label = "control",
DestPage = typeof(ControllerPages.Control)
},
new NavMenuItem()
{
Symbol = Symbol.More,
Label = "misc",
DestPage = typeof(ControllerPages.Misc)
},
};
public MainPage()
{
instance = this;
this.InitializeComponent();
DataContext = App.ViewModel;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
NavigationCacheMode = NavigationCacheMode.Enabled;
discoverer = new Discovery();
discoverer.StartedSearching += new Discovery.StartedSearchingDelegate(discoverer_StartedSearching);
discoverer.SearchingEnded += new Discovery.SearchingEndedDelegate(discoverer_SearchingEnded);
discoverer.TvFound += new Discovery.TvFoundDelegate(discoverer_TvFound);
}
private void OnBackRequested(object sender = null, BackRequestedEventArgs e = null)
{
if (TextInputOverlay.Visibility == Visibility.Visible)
{
TextInputOverlay.Visibility = Visibility.Collapsed;
if (e != null)
{
e.Handled = true;
}
txtInput.Text = "";
frame.Focus(FocusState.Programmatic);
}
else if (discoverer.HandleBackButton())
{
if (e != null)
{
e.Handled = true;
}
}
else
{
if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
}
public static string GetVersionNumber()
{
int major, minor;
if (GetVersion(out major, out minor))
{
return major + "." + minor;
}
return "1.0";
}
public static bool GetVersion(out int Major, out int Minor)
{
try
{
var asm = typeof(MainPage).GetTypeInfo().Assembly;
var parts = asm.FullName.Split(',');
var version = parts[1].Split('=')[1].Split('.');
Major = Convert.ToInt32(version[0]);
Minor = Convert.ToInt32(version[1]);
return true;
}
catch (Exception) { }
Major = 0;
Minor = 0;
return false;
}
public static void SendKey(EKey key)
{
if (directConn != null && bEnabled)
{
directConn.SendKey(key);
}
}
public static void SendText(string text)
{
if (directConn != null && bEnabled)
{
directConn.SendText(text);
}
}
#region discovery callbacks and processing
async void discoverer_SearchingEnded(Discovery.SearchEndReason reason)
{
switch (reason)
{
case Discovery.SearchEndReason.Error:
bEnabled = false;
SetProgressText("TV search failed.");
ToggleProgressBar(true);
break;
case Discovery.SearchEndReason.TimedOut:
default:
if (App.ViewModel.TvItems.Count == 0)
{
bEnabled = false;
SetProgressText("Timed out searching for a TV.");
await btnDemoMode.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
btnDemoMode.Visibility = Visibility.Visible;
});
ToggleProgressBar(true);
}
else
{
ToggleProgressBar(false);
}
break;
}
}
async void discoverer_TvFound(Windows.Networking.HostName TvHost, UInt16 TvPort, string TvResponse)
{
ToggleProgressBar(false);
SetProgressText("Found TV.");
await AddTvUnique(TvHost, TvPort);
await GetTvNameFrom(TvHost, TvPort, TvResponse);
}
async void discoverer_StartedSearching()
{
ToggleProgressBar(true);
SetProgressText("Searching for TV...");
bEnabled = true;
await btnDemoMode.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
btnDemoMode.Visibility = Visibility.Collapsed;
});
}
private async Task<string> GetTvNameFrom(Windows.Networking.HostName TvHost, UInt16 TvPort, string tvData)
{
var tvDataLines = tvData.Split('\n');
var TvKeyValuePairs = new Dictionary<string, string>();
foreach (var line in tvDataLines)
{
string key = null, value = null;
for (int i = 0; i < line.Length; i++)
{
if (line[i] == ':')
{
key = line.Substring(0, i).Trim();
value = line.Substring(i + 1).Trim();
break;
}
}
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
{
TvKeyValuePairs.Add(key.ToLower(), value);
}
}
if (TvKeyValuePairs.Count > 0)
{
await SetMetaDataForTv(TvHost, TvKeyValuePairs);
if (TvKeyValuePairs.ContainsKey("location"))
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
var resp = System.Text.Encoding.UTF8.GetString(await client.GetByteArrayAsync(TvKeyValuePairs["location"]));
var doc = XDocument.Parse(resp);
string tvName = doc.Descendants().Where(x => x.Name.LocalName == "friendlyName").First().Value;
await SetTvName(TvHost, tvName);
}
}
return null;
}
#endregion
#region utilities
private async Task SetTvName(Windows.Networking.HostName TvHost, string TvName)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
foreach (var i in App.ViewModel.TvItems)
{
if (i.TvAddress == TvHost.ToString())
{
i.TvName = TvName;
break;
}
}
});
}
private async Task SetMetaDataForTv(Windows.Networking.HostName TvHost, Dictionary<string, string> TvKeyValuePairs)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
foreach (var i in App.ViewModel.TvItems)
{
if (i.Equals(TvHost))
{
i.TvMetaData = TvKeyValuePairs;
break;
}
}
});
}
async Task AddTvUnique(Windows.Networking.HostName TvHost, UInt16 TvPort)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
foreach (var i in App.ViewModel.TvItems)
{
if (i.Equals(TvHost))
{
return;
}
}
App.ViewModel.TvItems.Add(new TvItemViewModel()
{
Port = TvConnection.TvDirectPort.ToString(),
TvAddress = TvHost.ToString(),
});
});
}
async void SetProgressText(string text)
{
System.Diagnostics.Debug.WriteLine(text);
await progressText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
progressText.Text = text;
});
}
public static async Task DisplayOkBox(string message, string title = null)
{
if (CoreWindow.GetForCurrentThread() == null)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await InternalDisplayOkBox(message, title);
});
}
else
{
await InternalDisplayOkBox(message, title);
}
}
private static async Task InternalDisplayOkBox(string message, string title = null)
{
MessageDialog msg = null;
if (title == null)
{
msg = new MessageDialog(message);
}
else
{
msg = new MessageDialog(message, title);
}
msg.Commands.Add(new UICommand("OK"));
await msg.ShowAsync();
}
public static async Task DisplayYesNoBox(string message, string title = null, UICommandInvokedHandler YesHandler = null, UICommandInvokedHandler NoHandler = null)
{
if (CoreWindow.GetForCurrentThread() == null)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
await InternalDisplayYesNoBox(message, title, YesHandler, NoHandler);
});
}
else
{
await InternalDisplayYesNoBox(message, title, YesHandler, NoHandler);
}
}
private static async Task InternalDisplayYesNoBox(string message, string title = null, UICommandInvokedHandler YesHandler = null, UICommandInvokedHandler NoHandler = null)
{
MessageDialog msg = null;
if (title == null)
{
msg = new MessageDialog(message);
}
else
{
msg = new MessageDialog(message, title);
}
msg.Commands.Add(new UICommand("Yes", YesHandler));
msg.Commands.Add(new UICommand("No", NoHandler));
await msg.ShowAsync();
}
#endregion
#region button/app event handlers
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
if (bFirstLoad)
{
await ConditionalFindDevices();
}
bFirstLoad = false;
frame.Navigate(typeof(ControllerPages.TvList));
}
private async Task ConditionalFindDevices()
{
bool bConnectedToNonCellNetwork = false;
var profiles = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();
foreach (var profile in profiles)
{
if (profile != null
&& (profile.IsWlanConnectionProfile || profile.NetworkAdapter.IanaInterfaceType == IanaInterfaceType_Ethernet || profile.NetworkAdapter.IanaInterfaceType == IanaInterfaceType_WiFi))
{
bConnectedToNonCellNetwork = true;
break;
}
}
ToggleProgressBar(true);
if (bConnectedToNonCellNetwork)
{
bEnabled = true;
discoverer.FindTvs();
}
else
{
SetProgressText("Remote disabled.");
btnDemoMode.Visibility = Visibility.Visible;
TransparentOverlay.Visibility = Visibility.Visible;
await DisplayOkBox("You must be connected to a non-cell network in order to connect to a TV. Connect to the same network as your device and try again.");
}
}
private async void ToggleProgressBar(bool? bEnableProgressBar = false)
{
if (!bEnableProgressBar.HasValue)
{
ToggleProgressBar(!customIndeterminateProgressBar.IsIndeterminate);
return;
}
await customIndeterminateProgressBar.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
customIndeterminateProgressBar.IsIndeterminate = bEnableProgressBar.Value;
if (bEnableProgressBar.Value)
{
if (!bEnabled)
{
customIndeterminateProgressBar.Visibility = Visibility.Collapsed;
customIndeterminateProgressBar.IsIndeterminate = false;
}
else
{
customIndeterminateProgressBar.Visibility = Visibility.Visible;
}
TransparentOverlay.Visibility = Visibility.Visible;
TransparentOverlay.Opacity = 0.85;
}
else
{
customIndeterminateProgressBar.Visibility = Visibility.Collapsed;
TransparentOverlay.Visibility = Visibility.Collapsed;
}
});
}
private void btnDemoMode_Click(object sender, RoutedEventArgs e)
{
bEnabled = false;
btnDemoMode.Visibility = Visibility.Collapsed;
ToggleProgressBar(false);
var rand = new Random((int)DateTime.Now.Ticks);
for (int i = 1; i <= 9; i++)
{
App.ViewModel.TvItems.Add(new TvItemViewModel()
{
Port = TvConnection.TvDirectPort.ToString(),
TvAddress = "192.168.100." + rand.Next(1, 255),
TvName = "Example TV " + i
});
}
}
private async void RefreshTvList_Click(object sender, RoutedEventArgs e)
{
App.ViewModel.TvItems.Clear();
await ConditionalFindDevices();
}
internal void OnQwertyButtonPressed(object sender, EventArgs args)
{
txtInput.Focus(FocusState.Programmatic);
TextInputOverlay.Visibility = Visibility.Visible;
}
private void txtInput_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
if (txtInput.Text.Length > 0)
{
SendText(txtInput.Text);
}
OnBackRequested();
}
}
private void txtInput_LostFocus(object sender, RoutedEventArgs e)
{
if (TextInputOverlay.Visibility == Visibility.Visible && (DateTime.Now - inputShown).TotalMilliseconds > 250)
{
OnBackRequested();
}
}
private void txtInput_GotFocus(object sender, RoutedEventArgs e)
{
inputShown = DateTime.Now;
}
internal void OnPowerButtonPressed(object sender, EventArgs args)
{
if (directConn != null && directConn.ConnectedHostName != null)
{
for (int i = App.ViewModel.TvItems.Count - 1; i >= 0; i--)
{
if (App.ViewModel.TvItems[i].TvAddress == directConn.ConnectedHostName.ToString())
{
App.ViewModel.TvItems.RemoveAt(i);
}
}
directConn.bSentPowerOff = true;
}
frame.Navigate(typeof(ControllerPages.TvList));
}
public static void NotifyAppFreshStart()
{
//bFirstLoad = true;
}
public static void NotifyAppDeactivated()
{
if (directConn != null)
{
directConn.NotifyAppDeactivated();
}
}
public static void NotifyAppActivated()
{
if (directConn != null)
{
directConn.NotifyAppActivated();
}
}
#endregion
#region direct connection handling/callbacks
internal void ConnectTo(Windows.Networking.HostName host, UInt16 port)
{
directConn = new TvConnection(host, port);
directConn.Connecting += new TvConnection.ConnectingDelegate(directConn_Connecting);
directConn.Connected += new TvConnection.ConnectedDelegate(directConn_Connected);
directConn.Disconnected += new TvConnection.DisconnectedDelegate(directConn_Disconnected);
directConn.Registering += new TvConnection.RegisteringDelegate(directConn_Registering);
directConn.RegistrationFailed += new TvConnection.RegistrationFailedDelegate(directConn_RegistrationFailed);
directConn.RegistrationAccepted += new TvConnection.RegistrationAcceptedDelegate(directConn_RegistrationAccepted);
directConn.RegistrationDenied += new TvConnection.RegistrationDeniedDelegate(directConn_RegistrationDenied);
directConn.RegistrationTimedOut += new TvConnection.RegistrationTimedOutDelegate(directConn_RegistrationTimedOut);
directConn.RegistrationWaiting += new TvConnection.RegistrationWaitingDelegate(directConn_RegistrationWaiting);
directConn.Connect();
}
async void directConn_Disconnected()
{
ToggleProgressBar(false);
SetProgressText("Disconnected from TV.");
if (directConn != null && !directConn.bSentPowerOff)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
OnPowerButtonPressed(null, null);
});
await DisplayOkBox("Lost connection to device.");
}
}
void directConn_Connected()
{
SetProgressText("Connected to TV. Sending registration...");
}
void directConn_RegistrationWaiting()
{
SetProgressText("Waiting for user authorization...");
}
async void directConn_RegistrationTimedOut()
{
SetProgressText("Remote connection timed out.");
await DisplayOkBox("Remote connection timed out.");
}
async void directConn_RegistrationDenied()
{
SetProgressText("Remote connection denied.");
await DisplayOkBox("Remote connection denied.");
}
void directConn_RegistrationAccepted()
{
SetProgressText("Remote approved!");
ToggleProgressBar(false);
}
async void directConn_RegistrationFailed()
{
SetProgressText("Sending remote registration failed.");
ToggleProgressBar(false);
await DisplayOkBox("Sending remote registration failed.");
}
void directConn_Registering()
{
SetProgressText("Registering remote with TV...");
}
void directConn_Connecting()
{
ToggleProgressBar(true);
SetProgressText("Connecting to TV at " + directConn.ConnectedHostName.ToString() + "...");
}
#endregion
private void Page_KeyUp(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Escape)
{
OnBackRequested();
e.Handled = true;
}
}
private void Page_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
App.OnCheckMouseBack(sender, e, () => { OnBackRequested(); });
}
private async void NavMenuList_ItemInvoked(object sender, ListViewItem listViewItem)
{
var navListSender = sender as NavMenuListView;
var item = navListSender.ItemFromContainer(listViewItem) as NavMenuItem;
if (item != null)
{
if (!item.OnInvoked(frame, sender))
{
// ugly, but immediately updating the navlist status was not working, so...
await Task.Delay(50);
SelectNavEntryMatching(frame.CurrentSourcePageType);
}
}
}
/// <summary>
/// Enable accessibility on each nav menu item by setting the AutomationProperties.Name on each container
/// using the associated Label of each item.
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void NavMenuItemContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (!args.InRecycleQueue && args.Item != null && args.Item is NavMenuItem)
{
args.ItemContainer.SetValue(AutomationProperties.NameProperty, ((NavMenuItem)args.Item).Label);
}
else
{
args.ItemContainer.ClearValue(AutomationProperties.NameProperty);
}
}
/// <summary>
/// Ensures the nav menu reflects reality when navigation is triggered outside of
/// the nav menu buttons.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnNavigatingToPage(object sender, NavigatingCancelEventArgs e)
{
SelectNavEntryMatching(e.SourcePageType);
}
private void SelectNavEntryMatching(Type type)
{
var item = (from p in NavMenuListControls.Items where (p as NavMenuItem).DestPage == type select p).FirstOrDefault();
if (item == null)
{
item = (from p in NavMenuList.Items where (p as NavMenuItem).DestPage == type select p).FirstOrDefault();
}
if (item == null && frame.BackStackDepth > 0)
{
// In cases where a page drills into sub-pages then we'll highlight the most recent
// navigation menu item that appears in the BackStack
foreach (var entry in frame.BackStack.Reverse())
{
item = (from p in this.navlist where p.DestPage == entry.SourcePageType select p).FirstOrDefault();
if (item != null)
{
break;
}
}
}
var NavMenu = NavMenuList;
var container = NavMenu.ContainerFromItem(item) as ListViewItem;
if (container == null)
{
NavMenu = NavMenuListControls;
container = NavMenu.ContainerFromItem(item) as ListViewItem;
}
// While updating the selection state of the item prevent it from taking keyboard focus. If a
// user is invoking the back button via the keyboard causing the selected nav menu item to change
// then focus will remain on the back button.
if (container != null)
{
container.IsTabStop = false;
NavMenuList.SetSelectedItem(container);
NavMenuListControls.SetSelectedItem(container);
container.IsTabStop = true;
}
}
private void OnNavigatedToPage(object sender, NavigationEventArgs e)
{
// After a successful navigation set keyboard focus to the loaded page
if (e.Content is Page && e.Content != null)
{
var control = (Page)e.Content;
control.Loaded += NavToPage_Loaded;
}
}
private void NavToPage_Loaded(object sender, RoutedEventArgs e)
{
(sender as Page).Focus(FocusState.Programmatic);
(sender as Page).Loaded -= NavToPage_Loaded;
this.CheckTogglePaneButtonSizeChanged();
}
/// <summary>
/// Callback when the SplitView's Pane is toggled open or close. When the Pane is not visible
/// then the floating hamburger may be occluding other content in the app unless it is aware.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TogglePaneButton_Checked(object sender, RoutedEventArgs e)
{
this.CheckTogglePaneButtonSizeChanged();
}
public Rect TogglePaneButtonRect
{
get;
private set;
}
public event TypedEventHandler<MainPage, Rect> TogglePaneButtonRectChanged;
/// <summary>
/// Check for the conditions where the navigation pane does not occupy the space under the floating
/// hamburger button and trigger the event.
/// </summary>
private void CheckTogglePaneButtonSizeChanged()
{
if (this.RootSplitView.DisplayMode == SplitViewDisplayMode.Inline ||
this.RootSplitView.DisplayMode == SplitViewDisplayMode.Overlay)
{
var transform = this.TogglePaneButton.TransformToVisual(this);
var rect = transform.TransformBounds(new Rect(0, 0, this.TogglePaneButton.ActualWidth, this.TogglePaneButton.ActualHeight));
this.TogglePaneButtonRect = rect;
}
else
{
this.TogglePaneButtonRect = new Rect();
}
var handler = this.TogglePaneButtonRectChanged;
if (handler != null)
{
handler.DynamicInvoke(this, this.TogglePaneButtonRect);
}
}
}
}