我有那个显示/隐藏传递功能,它工作得很好。我在下面说明的一个观点有一个安全代码,该效果也适用于具有属性“IsEnabled=False
”的条目文本。现在当我点击眼睛时没有任何事情发生。
如果没有启用文字输入,有没有办法让它工作?
<StackLayout Grid.Row="1" IsVisible="{Binding IsPINSectionVisible}">
<Label
Style="{StaticResource MessageLabelStyle}"
Text="{i18n:Translate Pin_Text}">
</Label>
</StackLayout>
<StackLayout Grid.Row="2" IsVisible="{Binding IsPINSectionVisible}">
<Entry Text="{Binding PIN.Value, Mode=TwoWay}"
IsEnabled="False"
IsPassword="True"
Placeholder="{i18n:Translate Pin_Title}">
<Entry.Style>
<OnPlatform x:TypeArguments="Style"
Android="{StaticResource EntryStyle}" />
</Entry.Style>
<Entry.Behaviors>
<behaviors:EventToCommandBehavior
EventName="TextChanged"
Command="{Binding ValidatePINCommand}" />
</Entry.Behaviors>
<Entry.Effects>
<effects:ShowHidePassEffect />
</Entry.Effects>
<Entry.Triggers>
<DataTrigger
TargetType="Entry"
Binding="{Binding PIN.IsValid}"
Value="False">
<Setter Property="behaviors:LineColorBehavior.LineColor"
Value="{StaticResource ErrorColor}" />
<Setter Property="Entry.PlaceholderColor"
Value="{StaticResource ErrorColor}" />
</DataTrigger>
</Entry.Triggers>
</Entry>
和Android效果类:
public class ShowHidePassEffect : PlatformEffect
{
protected override void OnAttached()
{
ConfigureControl();
}
protected override void OnDetached()
{
}
private void ConfigureControl()
{
EditText editText = ((EditText)Control);
editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, Resource.Drawable.pass_show_24, 0);
editText.SetOnTouchListener(new OnDrawableTouchListener());
}
}
public class OnDrawableTouchListener : Java.Lang.Object, Android.Views.View.IOnTouchListener
{
public bool OnTouch(Android.Views.View v, MotionEvent e)
{
if (v is EditText && e.Action == MotionEventActions.Up)
{
EditText editText = (EditText)v;
if (e.RawX >= (editText.Right - editText.GetCompoundDrawables()[2].Bounds.Width()))
{
if (editText.TransformationMethod == null)
{
editText.TransformationMethod = PasswordTransformationMethod.Instance;
editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, Resource.Drawable.pass_show_24, 0);
}
else
{
editText.TransformationMethod = null;
editText.SetCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, Resource.Drawable.pass_hide_24, 0);
}
return true;
}
}
return false;
}
}