-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationUtil.cs
72 lines (65 loc) · 2.07 KB
/
NavigationUtil.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MauiIssues
{
public static class NavigationUtil
{
public static void GoBack(string parameters = "")
{
var route = "..";
try
{
if (!string.IsNullOrEmpty(parameters))
route += "?" + parameters;
Shell.Current.GoToAsync(route);
}
catch (Exception ex)
{
// TODO: Proper error handling
if (ex == null) { }
throw;
}
}
/// <summary>
/// Navigates to a page specified by the page type
/// </summary>
/// <typeparam name="TPage"></typeparam>
public static void Navigate<TPage>() where TPage : ContentPage
{
Navigate<TPage>("");
}
/// <summary>
/// Navigates to a page specified by the page type
/// </summary>
/// <typeparam name="TPage"></typeparam>
/// <param name="parameters">Query parameters for the page.</param>
public static void Navigate<TPage>(string parameters) where TPage : ContentPage
{
try
{
string route = typeof(TPage).Name;
if (!string.IsNullOrEmpty(parameters))
route += "?" + parameters;
Shell.Current.GoToAsync(route);
}
catch (Exception ex)
{
// TODO: Proper error handling
if (ex == null) { }
throw;
}
}
/// <summary>
/// Navigates to a shell item specified in the AppShell
/// </summary>
/// <param name="shellItemName">The name of the shell item to navigate to</param>
public static void NavigateShell(string shellItemName)
{
ShellItem shellItem = (ShellItem)Shell.Current.FindByName(shellItemName);
Shell.Current.CurrentItem = shellItem;
}
}
}