Xamarin.forms 如果尚未打开,如何从App.xaml.cs打开页面
我有一个使用FreshMVVM的Xaml.Forms应用程序。我从app.xaml.cs打开一个特定页面,如下所示:Xamarin.forms 如果尚未打开,如何从App.xaml.cs打开页面,xamarin.forms,freshmvvm,Xamarin.forms,Freshmvvm,我有一个使用FreshMVVM的Xaml.Forms应用程序。我从app.xaml.cs打开一个特定页面,如下所示: Xamarin.Forms.Device.BeginInvokeOnMainThread(async () => { var navService = FreshIOC.Container.Resolve<IFreshNavigationService>(FreshMvvm.Constants.Defaul
Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
{
var navService = FreshIOC.Container.Resolve<IFreshNavigationService>(FreshMvvm.Constants.DefaultNavigationServiceName);
Page page = FreshPageModelResolver.ResolvePageModel<SomePageModel>();
await navService.PushPage(page, null);
...
});
Xamarin.Forms.Device.BeginInvokeMainThread(异步()=>
{
var navService=FreshIOC.Container.Resolve(FreshMvvm.Constants.DefaultNavigationServiceName);
Page Page=FreshPageModelResolver.ResolvePageModel();
等待navService.PushPage(第页,空);
...
});
但我需要添加一个检查,以防止这样做,如果这个页面已经打开。如何进行此类检查?在App类中添加一个静态布尔值,以检查页面是否已打开:
public partial class App : Application
{
public static bool isPageOpened;
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
public void test()
{
if (App.isPageOpened = false)
{
Xamarin.Forms.Device.BeginInvokeOnMainThread(async () =>
{
var navService = FreshIOC.Container.Resolve<IFreshNavigationService>(FreshMvvm.Constants.DefaultNavigationServiceName);
Page page = FreshPageModelResolver.ResolvePageModel<SomePageModel>();
App.isPageOpened = true;
await navService.PushPage(page, null);
});
}
}
}
谢谢你的回答。我想我可以用它。但首先我想问一下,有没有一种方法可以找出当前打开的页面?没有,我不认为有这种方法。您可以尝试检查导航。childern[0]。@DavidShochet我的解决方案对您有用吗?如果是,请您接受(单击☑️ 在这个答案的左上角),这样我们就可以帮助更多有同样问题的人:)。它确实有效,非常感谢!
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
App.isPageOpened = false;
}
}