【发布时间】:2021-02-24 08:28:01
【问题描述】:
在我的 Xamarin 应用程序中,我尝试使用更改 IsVisible 为 Frame 和 IsEnabled 为 Button,当密码被确认时(密码和确认密码应该有相同的文本),但是它没有改变任何东西。
具有讽刺意味的是,当应用程序打开时,默认情况下(没有输入任何值),Password.Text == ConfirmPassword.Text 为 True。
当两个Entry 字段的值相同时,我想更改它。谢谢。
.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;
}
}
【问题讨论】:
-
您有一个未定义的命名空间“x”。
-
@jdweng 感谢您的回复。当我使用
Name时,它说,找不到属性“名称”...并且它没有为x:Name返回任何错误,我认为它是在.xml 页面中的页面x:Class="Osma.Mobile.App.Views.PasswordPage",我说的对吗? -
t定义命名空间的地方会有xmlns:x="URL"
-
您需要为您的 if 添加一个条件,检查 !string.IsNullOrWhite(Password)
-
最初,当您在两个条目中启动应用程序时,有一个空格,密码和确认密码都相同,因此您编写的条件变为 true
标签: c# .net xamarin xamarin.forms