How to retain the pointer cursor on a custom button in a sub-classed / restyled TextBox? #10915
Replies: 2 comments 1 reply
-
|
I am not sure how you have implemented that additional button. But where ever I have to change the pointer, I surround that control with the below customized Frame (implemented for Hand cursor). This I learnt from various WinUI 3 discussions. |
Beta Was this translation helpful? Give feedback.
-
|
The SDK is probably applying custom cursor behaviors for the delete button but doesn't expose it to us, so you get the same behavior on your custom button when the name is the same. You can make a custom textbox class and override that textbox's OnApplyTemplate and match the behavior with the Protected cursor as hinted above. Use your custom textbox control instead of the default one in your xaml to see the behavior. CustomTextBlock.mp4 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Issue
I am sub-classing the TextBox control, and want to add another button in it which always appears, similarly to AutoSuggestBox. I followed how NumberBox and AutoSuggestBox are doing it, literally replicating the styles with minor adjustments. However, the cursor on the new button changes to beam, and not to a pointer like standard buttons.
<Button x:Name="NewButton" Grid.Row="1" Grid.Column="2" Style="{StaticResource DeleteButtonStyle}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="{TemplateBinding CornerRadius}" Padding="{ThemeResource HelperButtonThemePadding}" IsTabStop="False" Visibility="Visible" AutomationProperties.AccessibilityView="Raw" FontSize="{TemplateBinding FontSize}" Width="30" VerticalAlignment="Stretch"> <FontIcon Glyph="" FontFamily="{ThemeResource SymbolThemeFontFamily}" FontStyle="Normal" FontSize="{ThemeResource TextBoxIconFontSize}" /> </Button>A video illustrating the deffect:
2025-12-11_17-35-43.mp4
Weird enough, if I change the name of the change the name of my custom button to
DeleteButton, the cursor works as expected and changes to a pointer!A full reproducable example can be found here: https://github.com/mdobreva/TestCustomTextBox. The example adds the button by changing the style of the standard
TextBoxcontrol, but the effect is the same.I tried to lookup the source of TextBoxBase and TextBox, but nowhere I found how the cursor is changed / maintained. I couldn't find even how the mouse cursor is changed to beam in these controls.
What should I do to make the cursor of the new button working? And, why is the name of DeleteButton so special?
I am using Windows App Sdk 1.8 and .Net 10.
Beta Was this translation helpful? Give feedback.
All reactions