-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Implement custom text context menus to fix crashes #18854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
// Once the flyout was open once, we'll get Ctrl+A events and the TextBox will | ||
// ignore them. As such, we have to dig out the focused element as a fallback, | ||
// because otherwise Ctrl+A will be permanently broken. Put differently, | ||
// this is bodgy because WinUI 2.8 is buggy. There's no other solution here. |
Check failure
Code scanning / check-spelling
Unrecognized Spelling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess BODGY is allowed, but bodgy just ain't right
7c01c15
to
6770ace
Compare
<Setter Property="ContextFlyout"> | ||
<Setter.Value> | ||
<mtu:TextMenuFlyout /> | ||
</Setter.Value> | ||
</Setter> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this 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?
<Setter Property="ContextFlyout"> | ||
<Setter.Value> | ||
<mtu:TextMenuFlyout /> | ||
</Setter.Value> | ||
</Setter> |
There was a problem hiding this comment.
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).
<ItemGroup> | ||
<PRIResource Include="Resources\en-US\Resources.resw" /> | ||
</ItemGroup> |
There was a problem hiding this comment.
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
?
@@ -0,0 +1,35 @@ | |||
#pragma once |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#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>()) |
There was a problem hiding this comment.
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
?
// Once the flyout was open once, we'll get Ctrl+A events and the TextBox will | ||
// ignore them. As such, we have to dig out the focused element as a fallback, | ||
// because otherwise Ctrl+A will be permanently broken. Put differently, | ||
// this is bodgy because WinUI 2.8 is buggy. There's no other solution here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess BODGY is allowed, but bodgy just ain't right
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 theXamlRoot
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