Open lyahdav opened 3 years ago
@Austin-Lamb and @marb2000 FYI on an Islands issue.
A rather simple workaround for this is to create an instance of TextCommandBarFlyout
for each TextBox and TextBlock view you create in your XAML Islands app:
TextBlock textBlock;
TextCommandBarFlyout textBlockFlyout;
textBlock.ContextFlyout(textBlockFlyout);
textBlock.SelectionFlyout(textBlockFlyout);
TextBox textBox;
TextCommandBarFlyout textBoxFlyout;
textBox.ContextFlyout(textBoxFlyout);
textBox.SelectionFlyout(textBoxFlyout);
You could probably even go as far as to create a TextCommandBarFlyout per XamlRoot to save memory.
One thing that needs to be added to the workaround above to make the Flyout position correctly:
textBlockFlyout.Placement(xaml::Controls::Primitives::FlyoutPlacementMode::BottomEdgeAlignedLeft);
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Likely still relevant
WinAppSDK Xaml Islands doesn't have this same precise problem, but there are still some issues with this scenario so I'm leaving this open. Thanks all for posting information about workarounds.
Steps to reproduce the bug
Expected behavior TextBox context menu shows in 1st window. Instead the context menu doesn't show and 2nd window gets focused.
Screenshots https://user-images.githubusercontent.com/359157/124189731-08965c80-da76-11eb-9950-b481779be7fc.mov
Version Info Windows 10 21H1 / 19043.928 Islands
Additional context
Here's a backtrace of the code causing the wrong window to set focus. At the top of the stack (not shown) Xaml is sending a
WM_SETFOCUS
event to the wrong win32 window. I think what's happening is that TextBox.ContextFlyout is a singleton and it's not correctly updating the associated XamlIslandsRoot when it's opened. After opening a TextBox context menu the first time it gets set to that window's XamlIslandsRoot and then it never gets updated. I tried hooking into TextBox.ContextFlyout.Opening event and settingflyout.XamlRoot(flyout.Target().XamlRoot())
but that didn't help.