How to disable a button on AppShell, Xamarin.iOS

90 views Asked by At

I have on my AppShell, 3 ShellContent and my problem is that when I am in the second page or third or... in my route if I click on the ShellContent of my route it takes me back to the first page I would like to disable my button when I am on the same route, I don't have this problem on UWP, just on iOS, do you have an idea ?

I already tried IsEnabled="False", but it ignored it.

Here's a pic of my AppShell

AppShell

and here's my code

 <TabBar>

    <ShellContent x:Name="BureauShell" Title="Bureau" ContentTemplate="{DataTemplate local:ViewLogin}" Icon="office-desk.png"/>
    <ShellContent x:Name="ServicesShell" Title="Services" ContentTemplate="{DataTemplate local:ViewMenu}" Icon="booking.png"/>
    <ShellContent x:Name="PiecesShell" Title="Batiment" ContentTemplate="{DataTemplate local:ViewChat}" Icon="building.png" />
    
</TabBar>
1

There are 1 answers

2
Liqun Shen-MSFT On BEST ANSWER

Navigation can be canceled by invoking the Cancel method on the ShellNavigatingEventArgs object. Consider adding the following code in AppShell.cs:

    protected override void OnNavigating(ShellNavigatingEventArgs args)
    {
        base.OnNavigating(args);

        if(args.Current!=null)
        {
            if (args.Target.Location == args.Current.Location)
            {
                //You could add more logic
                Console.WriteLine("123");
                args.Cancel();
            }
        }
    }

Using the above code, the Navigation is cancelled if it is on the same route. You may add some more logic according to your case.

For more info, you could refer to Shell Navigation

Hope it helps!