Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 23, 2025

Root Cause of the Issue

On Android, when a user taps outside SfNumericEntry (e.g., on a Button), the native Entry loses focus but MAUI's focus state remains unchanged. This prevents OnLostFocus() from executing, blocking value updates and keyboard dismissal.

Description of Change

Added FocusChange event handler for Android that syncs native focus state with MAUI:

  • Handler Logic: Detects native focus loss while MAUI reports focused, then calls Unfocus() to trigger update sequence
  • Thread Safety: Captures local references before MainThread.BeginInvokeOnMainThread to prevent race conditions
  • Cleanup: Extracted CleanupAndroidEntryEvents() method, added to both handler changes and UnHookEvents()
  • Error Handling: Try-catch for ObjectDisposedException during async execution

Files Modified:

  • SfNumericEntry.cs: Added _androidEntry field
  • SfNumericEntry.Methods.cs: Added focus handler, cleanup method, updated handler logic
void AndroidEntry_FocusChange(object? sender, Android.Views.View.FocusChangeEventArgs e)
{
    var androidEntry = _androidEntry;
    var textBox = _textBox;
    
    if (sender == null || androidEntry == null || textBox == null || e.HasFocus)
        return;

    MainThread.BeginInvokeOnMainThread(() =>
    {
        try
        {
            if (textBox.IsFocused)
                textBox.Unfocus(); // Triggers OnLostFocus() -> UpdateValue() -> FormatValue()
        }
        catch (ObjectDisposedException) { }
    });
}

Issues Fixed

Fixes #

Screenshots

Not applicable - behavioral fix with no visual changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>SfNumericEntry error</issue_title>
<issue_description>### Description

<Label Text="时间" />
<SfNumericEntry Placeholder="请输入时间" Value="{Binding DurationSecond}" />
<Label Text="温度" />
<SfNumericEntry Placeholder="请输入时间" Value="{Binding TargetTemperature, Mode=TwoWay}" />
<Button Command="{Binding ConfirmCommand}" Text="确定" />
<Button Command="{Binding CancelCommand}" Text="取消" />

change TargetTemperature value , but the keyboard don't close. click button ,the value not change.

Steps to Reproduce

No response

.NET Version

.NET 10.0

Version with bug

1.0.7

Is this a regression from previous behavior?

Not sure, haven't tested other versions

Last Known Working Version

1.0.6

Affected platforms

Android

Affected Platform Versions

No response

Have you found a workaround?

No response

Relevant log output

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 7 commits November 23, 2025 15:41
…ntry

Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Co-authored-by: PaulAndersonS <42271912+PaulAndersonS@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SfNumericEntry keyboard not closing on value change Fix Android keyboard dismiss and value update on SfNumericEntry focus loss Nov 23, 2025
Copilot AI requested a review from PaulAndersonS November 23, 2025 15:54
Copilot finished work on behalf of PaulAndersonS November 23, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SfNumericEntry error

2 participants