0
votes

I need to navigate to a page, that will have shell flyout menu, but I don't need it present as item in menu.

I have tried routing pages

Routing.RegisterRoute("cart", typeof(Cart));

and then use

Shell.Current.GoToAsync("///cart");

But it throws an error, telling me about the only page in stack. Microsoft documentation doesn't help.

Global routes currently cannot be the only page on the stack, so absolute routing to global routes is not supported. For now, just navigate to: cart/

When I tried

Shell.Current.Navigation.PushAsync(new NavigationPage(new Cart()));

It worked, but topbar was default color and menu button wasn't there. Also, I have tried to push Cart as a new page, without new NavigationPage(), topbar has no changes, but menubutton works as BackButton, even though I set a Behaviour

<Shell.BackButtonBehavior>
        <BackButtonBehavior IconOverride="back.png"/>
</Shell.BackButtonBehavior>
3

3 Answers

2
votes

Using Shell.Current.GoToAsync will just push another page in your navigation stack,

If you want to navigate to another navigation page using shell, you can just create another Shell File, ex. AppShell.xaml(default for shell) and just change your MainPage by

Application.Current.MainPage = new NewAppShell();
0
votes

Cause:

Your path ///cart is invalid . Global routes currently can't be the only page on the navigation stack. Therefore, absolute routing to global routes is unsupported.

Solution:

Navigation can also be performed by specifying a valid relative URI as an argument to the GoToAsync method. The routing system will attempt to match the URI to a ShellContent object. Therefore, if all the routes in an application are unique, navigation can be performed by only specifying the unique route name as a relative URI:

await Shell.Current.GoToAsync("cart");
0
votes

i solved it through converter

<Shell.ItemTemplate>
        <DataTemplate>
             <Grid Style="{StaticResource FloutItemStyle}" IsVisible="{Binding Title,Converter={StaticResource boolConverter}}" Margin="0,0,0,5" BackgroundColor="#343434">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="1"/>
                </Grid.RowDefinitions>
                    <Label Text="{Binding Title}"
                       FontSize="Medium"
                       VerticalOptions="CenterAndExpand"                     
                       Margin="20,10,0,10" TextColor="#fbfbfb"/>
                <BoxView BackgroundColor="White"  Grid.Row="1"/>
            </Grid>
        </DataTemplate>
</Shell.ItemTemplate>

Converter

public class ConverterMenuItem : IValueConverter
{
    public ConverterMenuItem()
    {
    }

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (string.IsNullOrEmpty((string)value))
            return false;
        return true;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The decision is terrible)