microsoft-ui-xaml: BUG: AppBarButton click doesn't trigger focus loss on previously focused inputs
// EDIT: initially this was a proposal and it unfolded into a bug. To get the full context please read all comments
Proposal: NumberBox NumberChanged event
Summary
There is currently no way to get value updates from a NumberBox just-in-time as the user types (like you can with a TextBox.TexChanged event).
Rationale
Given the summary above, this forces developers to make workarounds to certain scenarios. Example scenario: We want to input a value and save the value to a file
- Given a form with a
NumberBoxhaving aValue={x:Bind MyProp, Mode=2way}andValueChanged="OnValChanged" - Given a
ButtonwithClick="OnClick"which passesMyPropto a method - When I input a number in the
NumberBox, and directly after that I click theButton - The
OnClicktriggers before theNumberBoxchange is picked up, thus passing an outdated value around.
In the case of a TextBox this annoying behavior can be worked around by having a TextChanged event handler which always updates MyProp just-in-time to be ready for being passed to the method invoked by OnClick
In the case of a NumberBox, there’s no way to work around this, other than redesigning the UI to have a modal which collects the NumberBox value, and then passes it to the called to be used.
Scope
| Capability | Priority |
|---|---|
| Just-in-time NumberBox value changes | Must |
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (2 by maintainers)
Oh right, I see. Sorry that I forgot the latest changes here, should have read this more carefully.
It’s a bit strange that the AppBarButton does not receive focus. @YuliKl @ranjeshj Is this behavior intended? Are there any reasons to not focus it here? @ccornici This is something that can definitely be fixed, I think the code that causes this behavior is the following line:
https://github.com/microsoft/microsoft-ui-xaml/blob/0a1f27bdf15ea36660a009b04306c786b56f3cf9/dev/CommonStyles/AppBarButton_themeresources.xaml#L114
Are you still interested in a NumberChanged/TextChanged event for the NumberBox control? If not, could you update the title to reflect the actual bug at hand here, i.e. AppBarButton not taking part in focus behavior?
I wonder if @ranjeshj saw you tagging him above @chingucoding 😄
I think it is, but I am not really sure when bindings get evaluated. It may be a bug, but I think it’s more based on the way bindings work in XAML. But again I am not sure on that.
Hmm, it seems that setting the focus inside the event handler only raises ValueChanged after it finished the handler it is in. There are two possible workarounds for your situation now I think:
ClickedSendAppBar) inside AppBarButton click function, and change focus. Inside ValueChanged check for that flag and if it is set, do what you would like to do, in the example app send money.