[英]how to make the tabbed page navigate when clicked on the same tab text/icon twice?
So i have a tabbed page, and there are several tabs associated with it所以我有一个标签页,并且有几个与之关联的标签
on the first tab i have a list, in which if i click a tile, lets say tile1, then i open up another page keeping the tabs intact, but what i want to is when i click the tab option1 again, then it should go to the main list, which is not happening any insight would be really helpful Clicking on "tile1", i do在第一个选项卡上我有一个列表,如果我单击一个图块,假设为 tile1,然后我打开另一个页面保持标签不变,但我想要的是当我再次单击选项卡选项 1 时,它应该是 go到主列表,这没有发生任何见解都会非常有帮助点击“tile1”,我愿意
await Navigation.PushAsync(new SubCategoryView());
which i assume is the correct way, and ironically enough intended behaviour works in iOS but not on Android我认为这是正确的方法,具有讽刺意味的是,预期的行为在 iOS 中有效,但在 Android 中无效
If you want to return to the root page when select the same tabbed, you can use Custom Renderer如果想在 select 同分页时返回根页面,可以使用Custom Renderer
using Android.Content;
using Android.Support.Design.Widget;
using xxx;
using xxx.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms.Platform.Android.AppCompat;
[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedRenderer))]
namespace xxx.Droid
{
public class MyTabbedRenderer : TabbedPageRenderer, TabLayout.IOnTabSelectedListener
{
public MyTabbedRenderer(Context context) : base(context)
{
}
private TabbedPage tabbed;
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
tabbed = (TabbedPage)e.NewElement;
}
else
{
tabbed = (TabbedPage)e.OldElement;
}
}
async void TabLayout.IOnTabSelectedListener.OnTabReselected(TabLayout.Tab tab)
{
await tabbed.CurrentPage.Navigation.PopToRootAsync();
}
}
}
using UIKit;
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using xxx;
using xxx.iOS;
[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedRenderer))]
namespace xxx.iOS
{
public class MyTabbedRenderer : TabbedRenderer
{
private TabbedPage tabbed;
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
tabbed = (TabbedPage)e.NewElement;
}
else
{
tabbed = (TabbedPage)e.OldElement;
}
try
{
var tabbarController = (UITabBarController)this.ViewController;
if (null != tabbarController)
{
tabbarController.ViewControllerSelected += OnTabbarControllerItemSelected;
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
private async void OnTabbarControllerItemSelected(object sender, UITabBarSelectionEventArgs eventArgs)
{
if (tabbed?.CurrentPage?.Navigation != null && tabbed.CurrentPage.Navigation.NavigationStack.Count > 0)
{
await tabbed.CurrentPage.Navigation.PopToRootAsync();
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.