Xamarin - 将textchange和unfocus事件分配给文本框(密码)

时间:2018-06-07 19:46:50

标签: xaml xamarin

我的XAML文件如下所示

   <local:PlainEntry IsPassword="True" Placeholder="Pwd"
    x:Name="contrasenaEntry" HorizontalOptions="Fill" 
    VerticalOptions="Center"  Text="{Binding Password, Mode=TwoWay}" Margin="0"/>

有没有办法在文本字段上触发和Onchange和unfocus事件密码我尝试使用Password.myElement.IsFocused它不起作用。我试过了

private void PasswordEditText_TextChanged(object sender, TextChangedEventArgs e)
{
    Console.WriteLine("text has changed!");
    // this is not working!
}

1 个答案:

答案 0 :(得分:0)

它显示你绑定了属性&#34;密码&#34;,这看起来像你正在使用MVVM,但是你写的那个方法看起来像是一个代码隐藏方法。

如果你正在使用代码,你会想要使用这样的东西..

<local:PlainEntry IsPassword="True" Placeholder="Pwd"
x:Name="contrasenaEntry" HorizontalOptions="Fill" 
VerticalOptions="Center" TextChanged="PasswordEditText_TextChanged" 
Margin="0"/>

然后调用您已有的方法

private void PasswordEditText_TextChanged(object sender, TextChangedEventArgs e)
{
    Console.WriteLine("text has changed!");
    // this is not working!
}