我的应用程序中有五个页面,如果App.quizRunning == true
并且当前页面是Japanese.PhrasesFrame
,我需要能够停止点击任何选项卡的操作:
namespace Japanese {
public partial class MainPage : TabbedPage {
public MainPage() {
InitializeComponent();
App.cardsPage = new Cards();
App.homePage = new HomePage();
App.helpPage = new HelpPage();
App.settingsPage = new SettingsPage();
App.phrasesPage = new PhrasesFrame(this);
Children.Add(App.navHomePage);
Children.Add(App.navHelpPage);
Children.Add(App.navSettingsPage);
Children.Add(App.navCardsPage);
Children.Add(App.navPhrasesFrame);
}
}
}
到目前为止,我已经提出了一个iOS解决方案。如果有人对此有任何疑问,请多多指教:
using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.Diagnostics;
using Japanese.Enums;
[assembly: ExportRenderer(typeof(TabbedPage), typeof(Japanese.iOS.TabbedPageRenderer))]
namespace Japanese.iOS {
public class TabbedPageRenderer : TabbedRenderer {
private MainPage _page;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null) { _page = (MainPage)e.NewElement; }
else { _page = (MainPage)e.OldElement; }
try {
var tabbarController = (UITabBarController)this.ViewController;
if (null != tabbarController)
tabbarController.ViewControllerSelected += OnTabbarControllerItemSelected;
}
catch (Exception exception) { Console.WriteLine(exception); }
}
private void OnTabbarControllerItemSelected(object sender, UITabBarSelectionEventArgs eventArgs)
{
if (!(_page.CurrentPage is Japanese.PhrasesFrame) && App.quizRunning == true) {
_page.CurrentPage = App.navPhrasesFrame;
}
}
}
}
现在我正在寻找Android解决方案,但根本找不到任何东西。
有人知道如何使用Android渲染器做到这一点吗?
答案 0 :(得分:1)
不确定您为什么不尝试CurrentPage = App.phrasesPage;
override protected void OnCurrentPageChanged() {
var a = this.CurrentPage;
if (Settings.mode == MO.Quiz && CurrentPage != App.phrasesPage) {
// give the user a confirmation/alert box and
// depending on the outcome set the variable
// App.continueQuiz to be true or false and then
// go back to Japanese.PhrasesFrame page
CurrentPage = App.phrasesPage;
}
}