question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.Net 7 Android Unfocused Entry Behavior only gets called when leaving the page

See original GitHub issue

Description

This works as expected in iOS. In Android, Unfocused only gets called when leaving the page. It does not get called when you leave the Entry field.

Steps to Reproduce

Create an Entry in Xaml.

<Entry Grid.Row="1" x:Name="nameEntry" Grid.Column="0" Placeholder="Enter a screen name." 
                               HorizontalOptions="Center" Style="{StaticResource Label_ProfileViewName}"
                               Text="{Binding SelectedPlayer.ScreenNameEntry}" TextChanged="entry_name_TextChanged" IsTextPredictionEnabled="false">
                       <Entry.Behaviors>
                           <local:CheckNameBehavior x:Name="checkScreenName"/>
                       </Entry.Behaviors>
                   </Entry>

Create a Behavior like so.

 public class CheckNameBehavior : Behavior<Entry>
    {
        static readonly BindablePropertyKey IsValidPropertyKey = BindableProperty.CreateReadOnly("IsValid", typeof(bool), typeof(CheckNameBehavior), false);
        static readonly BindableProperty IsValidProperty = IsValidPropertyKey.BindableProperty;

        public bool IsValid
        {
            get { return (bool)base.GetValue(IsValidProperty); }
            private set { base.SetValue(IsValidPropertyKey, value); }
        }

protected override void OnAttachedTo(Entry bindable)
        {
            bindable.Unfocused += HandleFocusChanged;
        }

protected override void OnDetachingFrom(Entry bindable)
        {
            bindable.Unfocused -= HandleFocusChanged;
        }

async void HandleFocusChanged(object sender, FocusEventArgs e)
        {
            Entry entry = sender as Entry;
        }
}

Link to public reproduction project repository

https://github.com/dotnet/maui/

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 31 with a target of 33

Did you find any workaround?

Nope, there is no workaround.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RsZolicommented, Aug 21, 2023

@PureWeen I can confirm that this is still happening! Can you please kindly answer, why is this being ignored for 8 months now? It basically prevents us from migrating to MAUI!

0reactions
AramMarcommented, Aug 21, 2023

@PureWeen i can also confirm the issue is still existed. and its very important for my app also

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - .NET MAUI Entry keyboard does not hide
Known bug. Removing the focus sometimes helps. Sometimes you need to do Disable/Enable in sequence. (I go with the second).
Read more >
AutoComplete in UI for .NET MAUI | Telerik Forums
On Android in order to unfocus the control, you need to call Unfocus() method or focusing another element that receives focus (another entry)....
Read more >
Entry - .NET MAUI
Gets or sets the opacity value applied to the element when it is rendered. This is a bindable property.
Read more >
Focused/Unfocused behaves differently on Android ...
On iOS it works fine, but on Android because focused is called first and then unfocused, wheelPicker becomes invisible which is wrong. Need ......
Read more >
SetFocusOnEntryCompletedBeh...
The SetFocusOnEntryCompletedBehavior is a Behavior that gives focus to a specified VisualElement when an Entry is completed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found