0
votes

I've implemented a hamburger menu in my Xamarin application following the official Microsoft example on how to create a hamburger menu using XAML and it works perfectly. Here is the code that is currently being used.

<ContentPage
         x:Class="MasterDetailPageNavigation.MasterPage"
         Icon="hamburger.png"
         Title="Personal Organiser">
<StackLayout>
    <ListView x:Name="listView" x:FieldModifier="public">
       <ListView.ItemsSource>
            <x:Array Type="{x:Type local:MasterPageItem}">
                <local:MasterPageItem Title="Contacts" IconSource="contacts.png" TargetType="{x:Type local:ContactsPage}" />
            </x:Array>
        </ListView.ItemsSource>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Padding="5,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

On small devices the hamburger menu is hidden by default which is the desired state. However when I test on a tablet device the hamburger menu is visible (open) by default. Is there an option so that I can state to always have the initial state of the hamburger menu to be hidden (closed)?

The tablet device I'm using is an Android device and its screen is relatively small and the hamburger menu being open by default is taking up too much screen space.

1

1 Answers

0
votes

I just had to add the following to my MainPage.xaml.cs Now the menu is hidden by default on all devices.

MasterBehavior = MasterBehavior.Popover;