75 lines
1.7 KiB
C#
75 lines
1.7 KiB
C#
|
using Xamarin.Forms;
|
|||
|
|
|||
|
namespace MobileApp1.Views
|
|||
|
{
|
|||
|
public class ContentPageHelper
|
|||
|
{
|
|||
|
|
|||
|
public static App GetApp(ContentPage view)
|
|||
|
{
|
|||
|
if (view == null) return null;
|
|||
|
|
|||
|
Element item = view.Parent;
|
|||
|
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (item == null) break;
|
|||
|
if (item is App) break;
|
|||
|
|
|||
|
item = item.Parent;
|
|||
|
}
|
|||
|
|
|||
|
return (item as App);
|
|||
|
}
|
|||
|
|
|||
|
public static Application GetApplication(ContentPage view)
|
|||
|
{
|
|||
|
if (view == null) return null;
|
|||
|
|
|||
|
Element item = view.Parent;
|
|||
|
|
|||
|
while (true)
|
|||
|
{
|
|||
|
if (item == null) break;
|
|||
|
if (item is Application) break;
|
|||
|
|
|||
|
item = item.Parent;
|
|||
|
}
|
|||
|
|
|||
|
return (item as Application);
|
|||
|
}
|
|||
|
|
|||
|
public static void SetMainPage(ContentPage view, Page page)
|
|||
|
{
|
|||
|
if (view == null) return;
|
|||
|
if (view.Parent == null) return;
|
|||
|
if (page == null) return;
|
|||
|
|
|||
|
Application rs = GetApplication(view);
|
|||
|
if (rs == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//rs.MainPage = new NavigationPage(new PasswordResetPage());
|
|||
|
rs.MainPage = page;
|
|||
|
}
|
|||
|
|
|||
|
public static async void PushMainPageNavigation(ContentPage view, Page page)
|
|||
|
{
|
|||
|
if (view == null) return;
|
|||
|
if (view.Parent == null) return;
|
|||
|
if (page == null) return;
|
|||
|
|
|||
|
Application rs = GetApplication(view);
|
|||
|
if (rs == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
await rs?.MainPage.Navigation.PushAsync(page);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|