更改 IsEnabled &在 Xamarin 中确认密码时可见 [英] Change IsEnabled & IsVisible on Password Confirmation in Xamarin
本文介绍了更改 IsEnabled &在 Xamarin 中确认密码时可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 Xamarin 应用程序中,我尝试使用更改 Frame
的 IsVisible
和 Button
的 IsEnabled
>,当密码被确认时(密码和确认密码应该有相同的文本),但它没有改变任何东西.
In my Xamarin App, I'm trying to use change the IsVisible
for Frame
and IsEnabled
for Button
, when the Password is Confirmed (Password & Confirm Password should've same text), but it isn't changing anything.
一个讽刺的是,当应用程序打开时,默认情况下(没有输入任何值),Password.Text == ConfirmPassword.Text
为 True.
One Irony is that when the App opens up, by default (there isn't any value entered), the Password.Text == ConfirmPassword.Text
is True.
当两个 Entry
字段的值相同时,我想更改它.谢谢.
I want to change it, when the Values of both Entry
fields are same. Thanks.
.xml 代码
<Entry
x:Name="Password"
IsPassword="True"
Keyboard="Numeric"
MaxLength="8"
ReturnType="Next" />
<Entry
x:Name="ConfirmPassword"
IsPassword="True"
Keyboard="Numeric"
MaxLength="8"
ReturnType="Done" />
<Frame x:Name="RedBar" BackgroundColor="#E1444D" IsVisible="true">
<BoxView />
</Frame>
<Frame x:Name="GreenBar" BackgroundColor="#24D27F" IsVisible="false">
<BoxView />
</Frame>
<Button
x:Name="PasswordButton"
IsEnabled="False"
Text="Submit">
</Button>
.xml.cs 代码
public PasswordPage()
{
InitializeComponent();
if (Password.Text == ConfirmPassword.Text)
{
RedBar.IsVisible = false;
GreenBar.IsVisible = true;
PasswordButton.IsEnabled = true;
}
else
{
RedBar.IsVisible = true;
GreenBar.IsVisible = false;
PasswordButton.IsEnabled = false;
}
}
推荐答案
Xaml 代码
<Entry
x:Name="Password"
IsPassword="True"
Keyboard="Numeric"
MaxLength="8"
ReturnType="Next" Unfocused="Password_Unfocused" />
<Entry
x:Name="ConfirmPassword"
IsPassword="True"
Keyboard="Numeric"
MaxLength="8"
ReturnType="Done" Unfocused="ConfirmPassword_Unfocused"/>
<Frame x:Name="RedBar" BackgroundColor="#E1444D" IsVisible="true">
<BoxView />
</Frame>
<Frame x:Name="GreenBar" BackgroundColor="#24D27F" IsVisible="false">
<BoxView />
</Frame>
<Button
x:Name="PasswordButton"
Clicked="PasswordButton_Clicked"
IsEnabled="False"
Text="Submit">
</Button>
背后的代码
public PasswordPage()
{
InitializeComponent();
ValidatePassword();
}
private void Password_Unfocused(object sender, FocusEventArgs e)
{
ValidatePassword();
}
private void ConfirmPassword_Unfocused(object sender, FocusEventArgs e)
{
ValidatePassword();
}
private void ValidatePassword()
{
if (!string.IsNullOrEmpty(Password.Text) && !string.IsNullOrEmpty(ConfirmPassword.Text))
{
if (Password.Text == ConfirmPassword.Text)
{
RedBar.IsVisible = false;
GreenBar.IsVisible = true;
PasswordButton.IsEnabled = true;
}
else
{
RedBar.IsVisible = true;
GreenBar.IsVisible = false;
PasswordButton.IsEnabled = false;
}
}
else
{
RedBar.IsVisible = true;
GreenBar.IsVisible = false;
PasswordButton.IsEnabled = false;
}
}
这篇关于更改 IsEnabled &在 Xamarin 中确认密码时可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文