question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MenuFlyout crashes in Xaml Islands

See original GitHub issue

Describe the bug When opening submenus in quick succession in MenuFlyout on Xaml Islands, there is a chance it can crash the whole program.

Steps to reproduce the bug

  1. Create a new blank WPF .NET Framework app.
  2. Add the Microsoft.Toolkit.Wpf.UI.XamlHost NuGet package.
  3. Add a project reference to the UniversalApiContract winmd from the Windows SDK.
  4. Add an app manifest to the app, and within <compatibility> add <maxversiontested Id="10.0.19041.0" />
  5. In MainWindow.xaml, write the following
    <Window x:Class="WpfApp2.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp2" xmlns:xamlhost="clr-namespace:Microsoft.Toolkit.Wpf.UI.XamlHost;assembly=Microsoft.Toolkit.Wpf.UI.XamlHost"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            <xamlhost:WindowsXamlHost x:Name="host" />
        </Grid>
    </Window>
    
  6. In MainWindow.xaml.cs, write this code
    public partial class MainWindow : Window
    {
        private Windows.UI.Xaml.Controls.MenuFlyoutSubItem MakeSubMenu(int i)
        {
            var sub = new Windows.UI.Xaml.Controls.MenuFlyoutSubItem
            {
                Text = $"Submenu {i}"
            };
    
            foreach (var j in Enumerable.Range(0, 10))
            {
                sub.Items.Add(new Windows.UI.Xaml.Controls.MenuFlyoutItem
                {
                    Text = $"Item {j}"
                });
            }
    
            return sub;
        }
    
        public MainWindow()
        {
            InitializeComponent();
    
            var rect = new Windows.UI.Xaml.Shapes.Rectangle
            {
                Fill = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red),
                Width = 50,
                Height = 50
            };
    
            var flyout = new Windows.UI.Xaml.Controls.MenuFlyout();
            foreach (var i in Enumerable.Range(0, 10))
            {
                flyout.Items.Add(MakeSubMenu(i));
            }
    
            rect.ContextFlyout = flyout;
            host.Child = rect;
        }
    }
    
  7. Launch the app.
  8. Right-click on the red square
  9. Open different sub-menus in quick succession.

Expected behavior The app does not crash

Screenshots

Version Info

NuGet package version: [Microsoft.Toolkit.Wpf.UI.XamlHost 6.1.2]

Windows app type:

UWP Win32
Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context This also happens in my C+±based XAML islands app, so this is not an issue specific to the WCT WPF host, it just makes reproduction easier.

Here’s a video recording of the issue: https://imgur.com/pHTPAB2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sylveoncommented, Jun 29, 2021

Seems to be fixed in Windows 11, would appreciate the fix to be backported to Windows 10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xaml Islands Win32 MenuFlyoutSubItem crash
Run the app, open the menu, hover over the first SubItem until the menu animation starts playing, then quickly move to the second...
Read more >
Click of Button with Flyout crashes when built ...
Contains a Button with a MenuFlyout as its Flyout ... The app won't crash if the project with the XAMLPage is not referenced ......
Read more >
WinUI 3 Preview 4 is available
The library allows using WinUI XAML components in WPF, WinForm and native apps. ... WebView2 crash on click after opening MenuFlyout ...
Read more >
Microsoft release Windows UI Library 3 Preview 4
XAML Controls Gallery (WinUI 3 Preview 4 branch) ... WebView2 has wrong viewport size; WebView2 crash on click after opening MenuFlyout ...
Read more >
MenuFlyout Class (Windows.UI.Xaml.Controls)
Represents a flyout that displays a menu of commands.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found