Problem with routing after creating custom shell renderer tabbar

Artyom Voytenko 1 Reputation point
2021-03-10T11:13:47.43+00:00

Hello everybody! I made custom shell tabbar button according this topic https://forums.xamarin.com/discussion/185038/how-we-can-create-custom-tab-like-that-on-shell-tabbar . It works, but i have a question: how to direct users on some page after Click? Thanks.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,491 Reputation points Microsoft Vendor
    2021-03-10T12:19:02.667+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    You can add click event to image. when click the image send a messageCenter.

       private async void SetupLargeTab()  
               {  
                   var todoTabBar = (TodoTabBar)ShellItem;  
                   var layout = new FrameLayout(Context);  
         
                   var imageHandler = todoTabBar.LargeTab.Icon.GetHandler();  
                   Bitmap bitmap = await imageHandler.LoadImageAsync(todoTabBar.LargeTab.Icon, Context);  
                   var image = new ImageView(Context);  
                   image.SetImageBitmap(bitmap);  
                   image.Click += Image_Click;  
                   layout.AddView(image);  
         
                   var lp = new FrameLayout.LayoutParams(200, 200);  
                   _bottomView.Measure((int)MeasureSpecMode.Unspecified, (int)MeasureSpecMode.Unspecified);  
                   lp.BottomMargin = _bottomView.MeasuredHeight / 2;  
         
                   layout.LayoutParameters = lp;  
         
                   _shellOverlay.RemoveAllViews();  
                   _shellOverlay.AddView(layout);  
               }  
         
               private void Image_Click(object sender, System.EventArgs e)  
               {  
                    
                   MessagingCenter.Send<App, string>(App.Current as App, "OneMessage","");  
               }  
    

    Then in the AppShell, you can Subscribe the message. Making a navigation, I navigate to the Page1

       public partial class AppShell : Xamarin.Forms.Shell  
           {  
               public AppShell()  
               {  
                   InitializeComponent();  
         
                   Routing.RegisterRoute("Page1", typeof(Page1));  
         
         
                   MessagingCenter.Subscribe<App, string>(App.Current, "OneMessage", (snd, arg) =>  
                   {  
                       Device.BeginInvokeOnMainThread( async() => {  
                           //Navigation.PushAsync(new NavigationPage(new DetailsInfo(arg)));  
         
                           await Shell.Current.GoToAsync("Page1");  
                       });  
                   });  
               }  
           }  
    

    Here is running screenshot.

    76371-image.png

    76305-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.