Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best approach for show/hide password toggle functionality in Xamarin traditional approach

We are working on show/ hide password toggle functionality in Xamarin traditional approach. What is the best place to implement it? Is it in Xamarin.iOS &. Droid or in Xamarin.Core?

If it is in Xamarin.Core, can you let us know the process. Is it by value convertors?

Thanks in advance.

like image 342
Ramgopal Reddy Bovilla Avatar asked Oct 20 '25 01:10

Ramgopal Reddy Bovilla


1 Answers

Recently, Microsoft MVP Charlin, wrote an article showing how to do this using Event Triggers in the Xamarin Forms code:

GIF Showing Show and Hide Functionality

She was able to do it simply using a new ShowPasswordTriggerAction of type TriggerAction that implemented INotifyPropertyChanged. Therein, she created a HidePassword bool property that Invoke a PropertyChanged event which changes the Source of the Icon image:

protected override void Invoke(ImageButton sender)
{
    sender.Source = HidePassword ? ShowIcon : HideIcon;
    HidePassword = !HidePassword;
}

Then place the Entry and ImageButton inside a layout (like a Frame or horizontally oriented LinearLayout) as shown:

  <Entry Placeholder="Password"
         IsPassword="{Binding Source={x:Reference ShowPasswordActualTrigger}, Path=HidePassword}"/>
  <ImageButton VerticalOptions="Center"
               HeightRequest="20"
               HorizontalOptions="End"
               Source="ic_eye_hide">
                   <ImageButton.Triggers>
                        <EventTrigger Event="Clicked">
                             <local:ShowPasswordTriggerAction ShowIcon="ic_eye"
                                                              HideIcon="ic_eye_hide"
                                                              x:Name="ShowPasswordActualTrigger"/>
                         </EventTrigger>
                  </ImageButton.Triggers>
  </ImageButton>
like image 152
Saamer Avatar answered Oct 22 '25 05:10

Saamer