This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
FirstView.xaml.cs
99 lines (85 loc) · 3.41 KB
/
FirstView.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
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using MvvmCrossUWP.Core.ViewModels;
namespace MvvmCrossUWP.Win.Views
{
public sealed partial class FirstView : BaseView
{
public static FirstView Current = null;
public Frame AppFrame { get { return (Frame)this.WrappedFrame.UnderlyingControl; } }
public FirstViewModel Vm => (FirstViewModel)ViewModel;
public FirstView()
{
this.InitializeComponent();
this.Loaded += (sender, args) =>
{
Current = this;
this.TogglePaneButton.Focus(FocusState.Programmatic);
};
this.RootSplitView.RegisterPropertyChangedCallback(
SplitView.DisplayModeProperty,
(s, a) =>
{
// Ensure that we update the reported size of the TogglePaneButton when the SplitView's
// DisplayMode changes.
this.CheckTogglePaneButtonSizeChanged();
});
SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;
}
private void SystemNavigationManager_BackRequested(object sender, BackRequestedEventArgs e)
{
if (!e.Handled && this.AppFrame.CanGoBack)
{
e.Handled = true;
this.AppFrame.GoBack();
}
}
public Rect TogglePaneButtonRect
{
get;
private set;
}
/// <summary>
/// An event to notify listeners when the hamburger button may occlude other content in the app.
/// The custom "PageHeader" user control is using this.
/// </summary>
public event TypedEventHandler<FirstView, Rect> TogglePaneButtonRectChanged;
/// <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();
}
/// <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(this, this.TogglePaneButtonRect);
handler.DynamicInvoke(this, this.TogglePaneButtonRect);
}
}
}
}