-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathBackButton.cs
62 lines (56 loc) · 1.78 KB
/
BackButton.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
//
// Copyright Fela Ameghino 2015-2025
//
// Distributed under the GNU General Public License v3.0. (See accompanying
// file LICENSE or copy at https://www.gnu.org/licenses/gpl-3.0.txt)
//
using Telegram.Common;
using Telegram.Navigation;
using Windows.UI.Xaml.Controls;
namespace Telegram.Controls
{
public partial class BackButton : GlyphButton
{
public BackButton()
{
DefaultStyleKey = typeof(BackButton);
Click += OnClick;
}
private void OnClick(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var master = this.GetParent<MasterDetailView>();
if (master != null)
{
if (master.NavigationService != null && master.NavigationService.CanGoBack)
{
master.NavigationService.GoBack();
return;
}
}
var page = this.GetParent<Page>();
if (page != null)
{
if (page is INavigablePage navigable)
{
var args = new BackRequestedRoutedEventArgs();
navigable.OnBackRequested(args);
if (args.Handled)
{
return;
}
}
if (page.DataContext is ViewModelBase viewModel && viewModel.NavigationService.CanGoBack)
{
viewModel.NavigationService.GoBack();
return;
}
else if (page.Frame != null && page.Frame.CanGoBack)
{
page.Frame.GoBack();
return;
}
}
BootStrapper.Current.RaiseBackRequested();
}
}
}