Skip to content

Conversation

@lhecker
Copy link
Member

@lhecker lhecker commented Apr 29, 2025

This works around a bug in WinUI where it creates a single context menu/flyout for text elements per thread, not per XamlRoot, similar to many other areas. Since the XamlRoot cannot change after creation, this means that once you've opened the flyout, you're locked into that window (= XAML root) forever. You can't open the flyout in another window and once you've closed that window, you can't open it anywhere at all.

Closes #18599

Validation Steps Performed

  • Flies out right click in the
    • About dialog ✅
    • Search dialog ✅
    • Word delimiters setting ✅
    • Launch size setting ✅
  • Across two windows ✅

@lhecker lhecker force-pushed the dev/lhecker/18599-context-menu branch from 7c01c15 to 6770ace Compare April 29, 2025 16:45
Comment on lines +135 to +139
<Setter Property="ContextFlyout">
<Setter.Value>
<mtu:TextMenuFlyout />
</Setter.Value>
</Setter>
Copy link
Member Author

@lhecker lhecker Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do this app-wide? This here fixes almost all occurrences of selectable text, thankfully.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the only thing I can think of is doing it similar to above, but without an x:Key value, so it would apply it to all the textboxes. Like this:

<!--- BODGY: <reason> --->
<Style BasedOn="{StaticResource DefaultTextBoxStyle}"
       TargetType="TextBox">
   <Setter Property="ContextFlyout">
      <Setter.Value>
         <mtu:TextMenuFlyout />
      </Setter.Value>
   </Setter>
</Style>

At the bug bash today, I think Dustin also suggested trying to add it at the App.xaml layer or something like that (probably the XAML file you import WinUI 2).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I may do this another time, if anything. My backlog of urgent work got a little long so I need to cut it short. 🙈

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix #18246 too?

Comment on lines +135 to +139
<Setter Property="ContextFlyout">
<Setter.Value>
<mtu:TextMenuFlyout />
</Setter.Value>
</Setter>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the only thing I can think of is doing it similar to above, but without an x:Key value, so it would apply it to all the textboxes. Like this:

<!--- BODGY: <reason> --->
<Style BasedOn="{StaticResource DefaultTextBoxStyle}"
       TargetType="TextBox">
   <Setter Property="ContextFlyout">
      <Setter.Value>
         <mtu:TextMenuFlyout />
      </Setter.Value>
   </Setter>
</Style>

At the bug bash today, I think Dustin also suggested trying to add it at the App.xaml layer or something like that (probably the XAML file you import WinUI 2).

Comment on lines 74 to 76
<ItemGroup>
<PRIResource Include="Resources\en-US\Resources.resw" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-checking: Just en-US?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the <OCResourceDirectory> key was missing.

@@ -0,0 +1,35 @@
#pragma once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#pragma once
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once

Probably also worth adding the BODGY comment here and referencing the GH issue for historical reasons.

@@ -0,0 +1,201 @@
#include "pch.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "pch.h"
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"

// > Common group of selectable controls with common actions
// > The I in MIDL stands for...
// No common interface.
if (const auto box = target.try_as<NumberBox>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about ComboBox with IsEditable=True?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we don't use those yet. I wonder if it's worth adding support for that in advance...

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Know if this fixes #18246 too?

@lhecker
Copy link
Member Author

lhecker commented May 14, 2025

I'll wait for the Canary build and test (and close) it then. Theoretically it should be fixed.

@lhecker lhecker merged commit 076746a into main May 14, 2025
19 checks passed
@lhecker lhecker deleted the dev/lhecker/18599-context-menu branch May 14, 2025 19:47
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.23 Servicing Pipeline Aug 21, 2025
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.23 Servicing Pipeline Aug 21, 2025
DHowett pushed a commit that referenced this pull request Aug 21, 2025
This works around a bug in WinUI where it creates a single context
menu/flyout for text elements per thread, not per `XamlRoot`, similar to
many other areas. Since the `XamlRoot` cannot change after creation,
this means that once you've opened the flyout, you're locked into that
window (= XAML root) forever. You can't open the flyout in another
window and once you've closed that window, you can't open it anywhere at
all.

Closes #18599

* Flies out right click in the
  * About dialog ✅
  * Search dialog ✅
  * Word delimiters setting ✅
  * Launch size setting ✅
* Across two windows ✅

(cherry picked from commit 076746a)
Service-Card-Id: PVTI_lADOAF3p4s4Axadtzgd5l-U
Service-Version: 1.23
@DHowett DHowett moved this from Cherry Picked to Shipped in 1.23 Servicing Pipeline Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

WinUI text context menu not showing up (Was: Crash when right clicking text)

3 participants