Xamarin.Forms - UWP Command behaves differently than on Android or IOS

dinobdinob USUniversity ✭✭✭
edited June 10 in Xamarin.Forms

I am having a very strange observation on UWP but not on Android or IOS.

I have Entry field like so

            <Entry x:Name="MyEntry" Text="{Binding EntryText}">
                <Entry.Behaviors>
                    <behaviorsPack:EventToCommandBehavior EventName="Completed" Command="{Binding EntryCompletedCommand}"/>
                </Entry.Behaviors>
            </Entry>

Above, Completed event is fired once EntryTextis provided and it is supposed to fire EntryCompletedCommand.

Below this entry, I have 2 buttons. One for Item-A and one for Item-B. These buttons have their own command OnButtonTappedwhich is called when user taps on them.

User can enter values into Entry view in 2 ways: (a) by tapping on Item-A or Item-B buttons or by scanning a barcode of these 2 buttons using an external barcode scanner.

Following these steps, everything works fine on Android or IOS:
1. User taps on Item-B button and Item-B is added to Entry view - this is all good
2. Next, user scans Item-A and Item-A is added to Entry view replacing Item-B - this is also all good on Android/IOS but not on UWP

However, on UWP, Item-B is added again in step 2 instead of adding Item-A. Only on UWP is that somehow Item-B was remembered and entered again whereas the same code works fine on Android and IOS.

I spent some time digging into this and what I see is that on Android or IOS, each scan will call EntryCompletedCommand command and each tap will call OnButtonTapped command.

UWP Inconsistancies with Command

  1. On UWP, the EntryCompletedCommand command is never called even if I dont first tap on a button. On Android and IOS, it is called correctly.
  2. On UWP and only after user first taps on button, a scan will call OnButtonTapped command **instead **of calling EntryCompletedCommand command. It is like on UWP, a previously tapped button will gets "remembered" and its command gets called instead of calling the EntryCompletedCommand.

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai
    edited June 11

    The event Completed will been called when user click the Enter in keyboard. So ,it is different between iOS and Android . You can call the method entry.SendCompleted(); It will called the event Completed manually .

  • dinobdinob USUniversity ✭✭✭

    @LucasZhang said:
    The event Completed will been called when user click the Enter in keyboard. So ,it is different between iOS and Android . You can call the method entry.SendCompleted(); It will called the event Completed manually .

    Thanks @LucasZhang Correct, the Completed is fired when user hits Enter or when scanned barcode contains LF at the end of scan and this is working just find on Android and IOS. It is the UWP that seem to be somehow "remembering" whatever was done last time. For example, if I tap on a button and after button even refocus on Entry, scan will trigger that button tap instead of Completed even though the Entry had focus which is what is so wired about it and the fact that same code misbehaves only on UWP.

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    Can you share a sample which contains the issue so that I can test it on my side .

Sign In or Register to comment.