-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Can't focus NumericUpDown #8069
Comments
For anyone facing the same issue, with a bit of prodding around, I managed to find a hackjob solution that involves navigating the public static void MyLayoutUpdatedHandler(object? sender, EventArgs? e){
// The ItemsControl from a template
var children = ((ItemsControl)sender).Presenter.Panel.LogicalChildren;
// The panel I use to lay my objects out
var pnl = (Panel)children[0].Child;
// The NumericUpDown. This is where the fun begins!
// For some reason, the VisualChildren Collection is not available on a Control, but it is on an IControl.
// Could cast the nud to one, I guess, but I need it for other stuff too.
Control nud = (Control)pnl.Children[^1];
// It's safe to assume a Parent exists, considering there's always the Window above us
((Control)nud.Parent!
// Grab the NumericUpDown again
.VisualChildren[^1]
// Then grab the ButtonSpinner,
.VisualChildren[0]
// The Border
.VisualChildren[0]
// The Grid
.VisualChildren[0]
// The ContentPresenter
.VisualChildren[0]
// And finally the TextBox
.VisualChildren[0]
).Focus(); // Focus() on nud should just redirect the call here imo, but it doesn't...
} |
probably the same issue: when clicking a Label with a NumericUpDown as target it does not result in a focused NumericUpDown element (avalonia 0.10.17) |
Hi, I solved it with the following lines of code:
|
Better than everyone is adding the same hack would be a PR to fix the actual issue. The issue is labled with help wanted, so a PR is welcome |
Describe the bug
NumericUpDown
elements can not receive focus, but some of its internal children can and should.Currently when calling
NumericUpDown.Focus()
, nothing happens with regard to visual and keyboard focus.This seems like a mistake, as one would expect the
TextBox
inside theNumericUpDown
template to become the focused object, with the caret being put inside of it, possibly selecting the numerical content of the box as well.To Reproduce
NumericUpDown
element, either through code behind or XAMLLayoutChanged
element of the parent container.Focus()
on the element and watch as nothing happens.Expected behavior
The focus and all keyboard input being put onto the
TextBox
inside of theNumericUpDown
(like how calling.Focus()
on aTextBox
works), or theNumericUpDown
element otherwise becoming focused and taking in user input.Desktop (please complete the following information):
Additional context
I've tried selecting its children elements directly, but I can't seem to access these from the code end of things.
The text was updated successfully, but these errors were encountered: