Ram*_*lla 4 xamarin.ios xamarin.android mvvmcross xamarin xamarin.forms
我们正在研究 Xamarin 传统方法中的显示/隐藏密码切换功能。实施它的最佳地点是什么?是在 Xamarin.iOS &. Droid 还是 Xamarin.Core?
如果是在 Xamarin.Core 中,您能否让我们知道该过程。是通过价值转换器吗?
提前致谢。
最近,Microsoft MVP Charlin撰写了一篇文章,展示了如何在 Xamarin Forms 代码中使用事件触发器来执行此操作:
她只需使用实现 INotifyPropertyChanged 的 TriggerAction 类型的新 ShowPasswordTriggerAction 即可完成此操作。其中,她创建了一个 HidePassword bool 属性,该属性调用 PropertyChanged 事件来更改图标图像的来源:
protected override void Invoke(ImageButton sender)
{
sender.Source = HidePassword ? ShowIcon : HideIcon;
HidePassword = !HidePassword;
}
Run Code Online (Sandbox Code Playgroud)
然后将 Entry 和 ImageButton 放置在布局内(如 Frame 或水平方向的 LinearLayout),如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6471 次 |
| 最近记录: |