Microsoft.Toolkit.Win32 icon indicating copy to clipboard operation
Microsoft.Toolkit.Win32 copied to clipboard

RichEditBox context menu doesn't work properly with multiple Xaml Islands

Open atiyka opened this issue 4 years ago • 5 comments

Describe the bug

In a WPF application (targeting .NET Core 3.1) I'm using XamlHosts to display windows 10 design UI elements. I'm using the UWP RichEditBox to allow the user to enter rich text. It's possible to open multiple windows inside my app, and each window contains a RichEditBox.

My first issue is that if I select a text inside the RichEditBox, a "small" context menu appears, where I can style the text (Bold, Italic and Underline). If I open the next window and select a text, the mentioned context menu will appear at the position of the previous window. (See the image below)

Steps to Reproduce

This can be easily reproduced by taking the xaml-islands sample and duplicating the island component with the following code (in WPF's MainWindow.xaml):

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <xaml:WindowsXamlHost InitialTypeName="Samples.ManagedUWP.MainPage" />
    <xaml:WindowsXamlHost InitialTypeName="Samples.ManagedUWP.MainPage" Grid.Row="1"/>
</Grid>

The other and bigger problem is that if I close the window, which was first open and where the little context menu always appears and then try to select some text on another window, the app crashes with the following exception:

The parameter is incorrect.

This happens because it can't display the context menu, since the first window was disposed.

What I tried:

  1. Searching for the error message, I tried to set TextWrapping = "NoWrap", but doesn't help.
  2. Tried to handle the ContextMenuOpening event, by setting e.Handled = true. This completely disables the context menus, the bigger context menu is also disabled (as I right click on the selected text)
  3. It would be great to disable just the little one, because the bigger menu appears at the correct place, but unfortunately the ContextMenuOpening event is called before the RightTapped event, so I can't know when the user right tapped and then allow the context menu to display.

Expected behavior

I would like to see the context menu where I select the text, or press the right button, not in another RichEditBox.

Screenshots

image

Environment

NuGet Package(s): 
Microsoft.Toolkit.Wpf.UI.XamlHost - version 6.1.2

Project .NET Version:
- [x] .NET Core 3.1

Windows 10 Build Number:
- [x] version 2004, os build 9041.746

App min and target version:
- [x] May 2019 Update (18362)

Device form factor:
- [x] Desktop

Visual Studio 
- [x] 2019 Community (version: 16.7.7)

atiyka avatar Feb 16 '21 11:02 atiyka

Hello atiyka, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Feb 16 '21 11:02 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Mar 03 '21 14:03 ghost

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.

ghost avatar Mar 18 '21 17:03 ghost

FYI @marb2000

michael-hawker avatar Mar 18 '21 22:03 michael-hawker

This issue still exists in the latest version of Windows 11 and it occurs with the context menu of Textboxes as well - the issue actually occurs in some preinstalled Windows apps as well such as Paint and Notepad, which both now use WinUI 2. Additionally, it seems to occur with UWP apps that use AppWindows as well. It might be worth reporting it here: https://github.com/microsoft/microsoft-ui-xaml.

aquinn39 avatar Sep 29 '22 18:09 aquinn39