-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Text fields unfocusing after validation error shows #373
Comments
It's strange WinUI 3 problem, I realized the same problem in WinUI 3 Gallery application. It automatically focuses a different element in the context when something changed in layout. I can implement the following workaround for inputfields: |
Ah, i see! |
I have the same issue for windows app
I just type one letter then I see directly a warning and the control loses focus! What it should suppose to be: I hope it will be fixing ASAP. Thank you |
After some research, I've discovered that Panels are focusable on windows and when a panel is focused it automatically delivers the focus event to its children recursively. If there is another textbox inside the same layout, it automatically focuses it because of this behavior. The same problem that dotnet/maui is dealing 👉 microsoft/microsoft-ui-xaml#3825 (comment) |
When you disable focusing for the parent element stackLayout.HandlerChanged+= (s,e)=>
{
if (stackLayout.Handler.PlatformView is Microsoft.Maui.Platform.LayoutPanel panel)
{
panel.AllowFocusOnInteraction = false;
panel.GettingFocus += (s, e) =>
{
e.Cancel = true;
};
}
}; Then none of the entries are focusable. WinUI is a little bit different from other platforms. We'll follow the dotnet/maui approach here when it's solved here dotnet/maui#11472 There is no 1 single best solution now |
At least you can try this custom TextField in your project to achieve showing validations when unfocused: public class MyTextField : TextField
{
#if WINDOWS
protected override void RegisterForEvents()
{
base.RegisterForEvents();
this.Unfocused += OnUnfocused;
}
protected override void ReleaseEvents()
{
base.ReleaseEvents();
this.Unfocused -= OnUnfocused;
}
protected override void CheckAndShowValidations()
{
// Leave empty
}
private void OnUnfocused(object sender, FocusEventArgs e)
{
base.CheckAndShowValidations();
}
#endif
} |
Not the best solution but a workaround has been released in |
thank you for your solution. I'll try it. |
You don't have to override in the latest version ( |
Normally I don't like to use beta versions, but it seems to be ok :) I'll try that first. Thank you again |
You can wait for tte stable version, It'll be released at the end of this week. I'm working on still |
THanks for the update! |
I'm using textfields I wanted users to only input numeric values, so i set a validation for such but
textfield.misbehaving.mp4
I wanted to implement a custom validation that would ensure that the textfield would simply NOT accept non-numeric characters, but it's still the same issue
As shown on the video below
textfield.misbehaving.w.custom.validation.mp4
The text was updated successfully, but these errors were encountered: