Я создал пользовательский элемент управления, содержащий запись и изображение.
ПРОБЛЕМА
Маска с паролем начинает работать после двух щелчков.
Изначально это так:
![enter image description here](https://i.stack.imgur.com/QzBVT.png)
Первый щелчок: Изменяет только значок
![enter image description here](https://i.stack.imgur.com/ldh3C.png)
Второй щелчок: Изменить шрифт и значок ![enter image description here](https://i.stack.imgur.com/MojnN.png)
После второго щелчка он работает правильно
РЕАЛИЗАЦИЯ
Пользовательский контроль
xml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
xmlns:control="clr-namespace:Projecro_3.ControlCostumiado"
prism:ViewModelLocator.AutowireViewModel="True"
Padding="10"
x:Class="Projecro_3.Controls.EntryControl">
<AbsoluteLayout>
<control:CustomEntry x:Name="entry"> </control:CustomEntry>
<Image x:Name="imgFinal" >
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="ImagemFinal_Tapped"
NumberOfTapsRequired="1" />
</Image.GestureRecognizers>
</Image>
</AbsoluteLayout>
</ContentView>
Класс:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class EntryControl : ContentView
{
public bool IsPassword
{
get
{
return (bool)GetValue(IsPasswordProperty);
}
set
{
SetValue(IsPasswordProperty, value);
}
}
public static readonly BindableProperty IsPasswordProperty = BindableProperty.Create(
propertyName: "IsPassword",
returnType: typeof(bool),
declaringType: typeof(EntryControl),
defaultValue: false,
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: IsPasswordPropertyChanged);
public EntryControl()
{
InitializeComponent();
entry.BindingContext = this;
}
private static void IsPasswordPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var control = (EntryControl)bindable;
if (control == null) return;
bool isPassword = (bool)newValue;
control.entry.IsPassword = isPassword;
control.imgFinal.Source = new FileImageSource { File = isPassword ? imageEyePassaword : imageEyeOffPassaword };
}
private void ImagemFinal_Tapped(object sender, EventArgs e)
{
IsPassword = !IsPassword;
}
private const string imageEyePassaword = "eye.png";
private const string imageEyeOffPassaword = "eye_off.png";
}
MainPage
<control:EntryControl IsPassword="True"></control:EntryControl>