Entry control is firing Focused event on every cursor blink

christopherpolskachristopherpolska PLUniversity ✭✭✭

Hi,

I found out that the Entry control's event "Focused" is being fired up every time the cursor blinks... So let's say you have simple code:
MyEntry.Focused += (object sender, FocusEventArgs e) =>{ someCode };
you start the app, you click in the entry, the cursor starts to blink -> every blink will fire up this code.

Do you guys think this is how the Focused should be used? I have reported this as a bug, any thoughts?

:)

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    @christopherpolska said:
    I found out that the Entry control's event "Focused" is being fired up every time the cursor blinks... So let's say you have simple code:
    MyEntry.Focused += (object sender, FocusEventArgs e) =>{ someCode };
    you start the app, you click in the entry, the cursor starts to blink -> every blink will fire up this code.

    Does "someCode" move the focus elsewhere, or have you got breakpoints in someCode, or are you stepping through the code in the debugger?

  • christopherpolskachristopherpolska PLUniversity ✭✭✭

    No it does not move it anywhere.
    Open VS and create a new solution (whatever, blank, tabbed, masterDetail); add an Entry to the xaml view, name it.
    In the constructor of that page, put the code I posted. You will see that with every cursor blink, it fires the focus event.
    Put breakpoint on the first bracket of that function.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Well... Entry doesn't behave like that for everyone else. Its not something the control does.

    So you've got something... somewhere... that is taking away focus, then returning it. Something in your code, not in Xamarin.

  • christopherpolskachristopherpolska PLUniversity ✭✭✭

    @ClintStLaurent said:
    Well... Entry doesn't behave like that for everyone else. Its not something the control does.

    So you've got something... somewhere... that is taking away focus, then returning it. Something in your code, not in Xamarin.

    Well...
    if you would read my post with more care and understanding, you would see this:

    Open VS and create a new solution

    Which means you can test it in less than 5 minutes! So test it, verify this and then write back... instead of just writing useless content.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    edited January 4

    There is nothing to test. I, like the other developers have been doing this for quite a long time. I know the control doesn't do what you describe in the numerous other apps I've built - nor does it do that on the multiple devices I work with.

    Honestly - I don't care for your combative attitude that its my job to follow your orders. I've been a senior developer for more than 20 years and I volunteer my time here to mentor new developers entering the field. You may not recognize what an amazing opportunity modern forums like this are compared to limited resources the previous generation of coders had - and therefore feel entitled and that everyone else is your serf. But there are plenty of other folks asking questions here who appreciate the help provided by the mentors, and know how to be respectful - or at the very least polite and civil.

    I'm bowing out of the conversation now.
    I wish you the best of luck with your issue.

  • christopherpolskachristopherpolska PLUniversity ✭✭✭
    edited January 4

    Well, you can be senior software ninja guru developer - whatever, it will not change the fact of your lack of professionalism - the time you spend on writing this post is longer than checking what actually I wrote. If you have felt that I am giving you orders then... I suppose you are not receiving enough recognition - that is, of course, sad, so let me do it: it is nice you have mentored so many people - and? How does it relate to the problem?
    You are saying that I do not appreciate the help? Where is help from your side - I see only a selfish statement like "I wrote 1000000 of apps and never had an issue"... sorry - this is ridiculous - there is nothing to appreciate for the time being.
    Just don't reply (that is an order!) because you are not bringing anything to this conversation.

  • TaylorDTaylorD USMember ✭✭✭

    Took your recommendation and created a new Xamarin.Forms solution and added an entry and the line provided by you. I added a Console.WriteLine("Hit") in the Focus method to see how many times it got hit.

    I tried the same code on all 3 platforms (Android, iOS, and UWP) and each platform only showed "Hit" once. Not sure why yours is getting hit everytime, but a new solution doesn't show the indicated error.

  • christopherpolskachristopherpolska PLUniversity ✭✭✭

    @TaylorD said:
    Took your recommendation and created a new Xamarin.Forms solution and added an entry and the line provided by you. I added a Console.WriteLine("Hit") in the Focus method to see how many times it got hit.

    I tried the same code on all 3 platforms (Android, iOS, and UWP) and each platform only showed "Hit" once. Not sure why yours is getting hit everytime, but a new solution doesn't show the indicated error.

    Great!
    Thanks for checking this.
    Please see this:
    https://gist.github.com/kkrzysiek/dcc94ddd9ea4a164531aab6d21720236

    Did you do it in a similar way? The popup in my case is displayed many times.

  • JohnHJohnH GBMember ✭✭✭✭✭

    DisplayAlert will take focus.

  • TaylorDTaylorD USMember ✭✭✭
    edited January 4

    ... That's happening because every time the DisplayAlert is dismissing your Entry is getting refocused. That's not a bug, but intended behavior. Every time the control focuses that event will fire. Meaning, every time that you dismiss your DisplayAlert, it gets focus again. It just happens to be on the cursor change.

    @JohnHardman said:
    Does "someCode" move the focus elsewhere, or have you got breakpoints in someCode, or are you stepping through the code in the debugger?

    @ClintStLaurent said:
    So you've got something... somewhere... that is taking away focus, then returning it. Something in your code, not in Xamarin.

    These two developers presented the issue of something taking the focus away correctly from the start. We were all unsure of what the somecode was and what was happening because it wasn't provided in the initial example.

  • JohnHardmanJohnHardman GBUniversity mod
    edited January 4

    @JohnHardman said:
    Does "someCode" move the focus elsewhere, or have you got breakpoints in someCode, or are you stepping through the code in the debugger?

    @christopherpolska said:
    No it does not move it anywhere.

    @christopherpolska said:
    Put breakpoint on the first bracket of that function.

    Now that we know what someCode does, and from your comment about adding breakpoints, it is clear that you are hitting one, or possibly two, of the things that I mentioned.

    When testing focus change event handlers, always use something that does not move the focus (e.g. System.Diagnostics.Debug.WriteLine or Console.WriteLine) and avoid putting breakpoints in the event handler (if testing a UWP build, or possibly - I haven't checked this as I use physical devices - if testing using a simulator/emulator).

Sign In or Register to comment.