2

I have an application implementing a secondary view based on the Microsoft MultipleView Sample. It uses the Menubar which is available with the NuGet package Microsoft.UI.XAML and I have noticed a very weird thing, the menus stop working if you show the main view from the secondary view but only if you have closed the main view using the X beforehand.

I wanted to make sure I hadn't done anything too stupid, so I re-downloaded the MultipleView Sample from the GitHub then did the following to implement the menubar

1) in Manage NuGet Packages I updated Microsoft .netCore to v6.2.10

2) I browsed for Microsoft.UI.XAML and install that (v2.4.2)

3) in app.aml after

<ResourceDictionary Source="/Styles/Styles.xaml"/>

add

<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />

4) in mainpage.xaml

after

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

add

xmlns:Custom="using:Microsoft.UI.Xaml.Controls"

5) in mainpage.xaml after

    <TextBlock x:Name="Header" Text="Universal Windows Platform sample" Style="{StaticResource TagLineTextStyle}" Margin="0,15,0,0" />

add

<Custom:MenuBar x:Name="theMenuBar">
                <Custom:MenuBarItem x:Name="TestMenu1" Title="TestA">
                    <MenuFlyoutItem Text="TestA Item" Click="TestA_Click"></MenuFlyoutItem>
                </Custom:MenuBarItem >
                <Custom:MenuBarItem x:Name="TestMenu2" Title="TestB">
                    <MenuFlyoutItem Text="TestB Item" Click="TestB_Click"></MenuFlyoutItem>
                </Custom:MenuBarItem >
                <Custom:MenuBarItem x:Name="TestMenu3" Title="TestC">
                    <MenuFlyoutItem Text="TestC Item" Click="TestC_Click"></MenuFlyoutItem>
                </Custom:MenuBarItem >
            </Custom:MenuBar>

6) In MainPage.xaml.cs add

private void TestA_Click(object sender, RoutedEventArgs e)
{

}
private void TestB_Click(object sender, RoutedEventArgs e)
{

}
private void TestC_Click(object sender, RoutedEventArgs e)
{

}

Now Build and run (I ran on a Windows 10 laptop using X64 local)

If you did the above, you should see the three menu items at the top just after the Universal Windows Platform Sample text block and if you click the menu the item in the menu will appear

Click on "Create new View" then select it in the Open Views and click "Show selected view as standalone.

Return to the main page, click the X to close the main window. The secondary window will now be topmost and in the secondary window click "Switch to main view". This will replace the content of the secondary frame with the main page

You may have to repeat the process (click create new view, select it, click "Show selected view as standalone., return to main view, close with X, then click "Switch to main view"

Now try to operate the menu items.

I've found that they don't work at all. Clicking on them does not fly-out the item as before.

What's really strange is that sometimes I've found that some of the three menus will stop working after the first close/"Switch to main view" iteration and other times it takes the second pass before they don't work. But once they stop working, they never start to work later

Now, I haven't really coded anything too much here, just added the menubar with items, so I'm pretty sure this isn't something I did. (Unless somewhere it's documented that Microsoft.UI.Xaml.Controls don't work with multipleViews).

One thing I have tried is changing the GoToMain_click routine to try a standalone window

ie replace

await ApplicationViewSwitcher.switchAsync(mainViewId);

to

var viewShown = await ApplicationViewSwitcher.tryShowAsStandaloneAsync(mainViewId);

It makes more sense to me to that when switching to the main view that the secondary view should stay open. However, it doesn't solve the problem, and in my test of that MenuA and MenuC stopped working but MenuB still worked and showed it's flyout item on the first pass, but a second iteration and all stopped working

All the code dealing with the views is stock Microsoft MultipleView Sample...and I'm not sure if the issue is with that sample code or with the menubar in the NuGet package.

Can anyone shed some light and hopefully give me a workaround to re-activate the menus?

greg
  • 309
  • 1
  • 7
  • I've reproduced this issue using the official sample. I checked the live visual tree when switching back to the main page. The menuitem shows in the live visual tree but it doesn't appear in the xaml. I'll do some further researching on this. – Roy Li - MSFT Jun 16 '20 at 05:31
  • Is there any workaround to get the menu working, for example is there some way I could force the XAML to reload? – greg Jul 23 '20 at 21:27
  • I and my teammate are still working on it. This is unexpected behavior. Would you mind if you could create a simple sample to reproduce this instead of modifying the official sample and share it with me, please? – Roy Li - MSFT Jul 28 '20 at 05:57
  • Hope you are doing well. I'm here to tell you that this issue has been recorded by the team and the team is investigating this. – Roy Li - MSFT Aug 13 '20 at 03:17
  • Any developments? It would be helpful to know if this stems from a shortfall of the official sample or a OS issue – greg Nov 20 '21 at 22:20

0 Answers0