nam
nam

Reputation: 23749

UWP Menu Bar not displaying

I followed the instructions from this article from official UWP team using VS2017 on my Windows 10 version 1809. But the following XAML is not showing menu bar. I've tested it on top of the app window and then even in the middle of the window but to no avail. I've also installed Windows UI Library following this article. What could be a reason and how to resolve the issue?

<Page
    x:Class="Junk_UWP.MainPage"
    xmlns:controls="using:Microsoft.UI.Xaml.Controls"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Junk_UWP"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid>
        <MenuBar Margin="0,338,0,622" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <MenuBarItem Title="File">
                <MenuFlyoutSubItem Text="New">
                    <MenuFlyoutItem Text="Plain Text Document"/>
                    <MenuFlyoutItem Text="Rich Text Document"/>
                    <MenuFlyoutItem Text="Other Formats..."/>
                </MenuFlyoutSubItem>
                <MenuFlyoutItem Text="Open..."/>
                <MenuFlyoutItem Text="Save"/>
                <MenuFlyoutSeparator/>
                <MenuFlyoutItem Text="Exit"/>
            </MenuBarItem>

            <MenuBarItem Title="Edit">
                <MenuFlyoutItem Text="Undo"/>
                <MenuFlyoutItem Text="Cut"/>
                <MenuFlyoutItem Text="Copy"/>
                <MenuFlyoutItem Text="Paste"/>
            </MenuBarItem>

            <MenuBarItem Title="Help">
                <MenuFlyoutItem Text="About"/>
            </MenuBarItem>
        </MenuBar>
        <Button Content="Button" HorizontalAlignment="Left" Margin="750,466,0,0" VerticalAlignment="Top" Click="Button_Click"/>

    </Grid>
</Page>

Snapshot of Design Page of above Xaml:

enter image description here

Upvotes: 1

Views: 958

Answers (1)

Ivan I
Ivan I

Reputation: 9990

The reason seems to be your huge vertical margins for the MenuBar. You need quite a big window and screen to display those margins. Also it doesn't make sense to use VerticalAlignment="Stretch", though I am not sure if it can break something.

Upvotes: 1

Related Questions