[Xamarin.Forms][Shell][XAML] Remove Shell Flyout Hamburguer Button WITHOUT disabling Flyout

Alberto Herrera 1 Reputation point
2020-12-07T06:41:49.973+00:00

I currently have this in my AppShell:

   <Shell  
       x:Class="Fighter_MoveList.AppShell"  
       xmlns="http://xamarin.com/schemas/2014/forms"  
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
       xmlns:d="http://xamarin.com/schemas/2014/forms/design"  
       xmlns:local="clr-namespace:Fighter_MoveList.Views"  
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
       Title="Fighter_MoveList"  
       FlyoutBehavior="Flyout"  
       FlyoutIcon=""  
       FlyoutIsPresented="False"  
       mc:Ignorable="d">  
     
       <!--  
           Styles and Resources  
       -->  
       <Shell.Resources>  
           <ResourceDictionary>  
               <Style x:Key="BaseStyle" TargetType="Element">  
                   <Setter Property="Shell.BackgroundColor" Value="{StaticResource PrimaryColor}" />  
                   <Setter Property="Shell.ForegroundColor" Value="White" />  
                   <Setter Property="Shell.TitleColor" Value="White" />  
               </Style>  
               <Style BasedOn="{StaticResource BaseStyle}" TargetType="ShellItem" />  
           </ResourceDictionary>  
       </Shell.Resources>  
       <local:RosterPage />  
   </Shell>  

This allows my app to work but it shows a hamburguer button with no content in Android and UWP.
UWP:
45517-image.png

I could change the FlyoutBehavior to disabled but this removes the back buttons on UWP, so that's not an option unfortunately.
I tried to change the FlyoutIcon to an empty string hoping the icon would disappear but it didnt.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2020-12-07T08:54:30.333+00:00

    Hello @Alberto Herrera Welcome to Microsoft Q&A,

    [Xamarin.Forms][Shell][XAML] Remove Shell Flyout Hamburguer Button WITHOUT disabling Flyout

    For your requirement, you could find shellrender style here, if you just want to disable hamburger menu button, you could find TogglePaneButton and set it Visibility="Collapsed". Then copy all the style content to UWP App.xaml file like the following

    <Application  
        x:Class="Xaminals.UWP.App"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        xmlns:contract4Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,4)"  
        xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)"  
        xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,7)"  
        xmlns:local="using:Xaminals.UWP"  
        xmlns:winui="using:Microsoft.UI.Xaml.Controls"  
        xmlns:xf="using:Xamarin.Forms.Platform.UWP">  
        <Application.Resources>  
            <ResourceDictionary>  
                <DataTemplate x:Key="ShellFlyoutBaseShellItemTemplate">  
                    <winui:NavigationViewItem x:Name="navItem">  
                        <xf:ShellFlyoutItemRenderer IsSelected="{Binding IsSelected, ElementName=navItem, Mode=TwoWay}"></xf:ShellFlyoutItemRenderer>  
                    </winui:NavigationViewItem>  
                </DataTemplate>  
                <DataTemplate x:Key="ShellFlyoutMenuItemTemplate">  
                    <winui:NavigationViewItem x:Name="navItem">  
                        <xf:ShellFlyoutItemRenderer IsSelected="{Binding IsSelected, ElementName=navItem, Mode=TwoWay}"></xf:ShellFlyoutItemRenderer>  
                    </winui:NavigationViewItem>  
                </DataTemplate>  
                <DataTemplate x:Key="ShellFlyoutSeperatorTemplate">  
                    <winui:NavigationViewItemSeparator />  
                </DataTemplate>  
                <DataTemplate x:Key="ShellSectionMenuItemTemplate">  
                    <winui:NavigationViewItem Content="{Binding Title}"/>  
                </DataTemplate>  
                <ItemsPanelTemplate x:Key="ShellToolbarItemsPanelTemplate">  
                    <StackPanel Orientation="Horizontal" />  
                </ItemsPanelTemplate>  
                <DataTemplate x:Key="ShellToolbarItemTemplate">  
                    <xf:ShellToolbarItemRenderer  ToolbarItem="{Binding}" Margin="0" Background="Transparent" BorderThickness="1" IsEnabled="{Binding IsEnabled}">  
                        <Grid>  
                            <Grid.ColumnDefinitions>  
                                <ColumnDefinition Width="Auto"></ColumnDefinition>  
                                <ColumnDefinition Width="Auto"></ColumnDefinition>  
                            </Grid.ColumnDefinitions>  
                            <Image  
    				    DataContext="{Binding IconImageSource, Converter={StaticResource ImageConverter}}" Source="{Binding Value}" VerticalAlignment="Center" />  
                            <TextBlock Grid.Column="1" Foreground="White" VerticalAlignment="Center" Text="{Binding Text}"></TextBlock>  
                        </Grid>  
                    </xf:ShellToolbarItemRenderer>  
                </DataTemplate>  
      
                <Style x:Key="ShellNavigationView" TargetType="xf:ShellRenderer">  
               ........  
    

    And above style will hidden Hamburguer button, but allow backbutton work.


    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.

    0 comments No comments