CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
384 stars 89 forks source link

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

Open atiyka opened 3 years ago

atiyka commented 3 years ago

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)
ghost commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

michael-hawker commented 3 years ago

FYI @marb2000

aquinn39 commented 1 year ago

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.