为了账号安全,请及时绑定邮箱和手机立即绑定

当输入字段不可见时,如何隐藏 Xamarin 表单中的错误标签?

当输入字段不可见时,如何隐藏 Xamarin 表单中的错误标签?

C#
qq_花开花谢_0 2023-09-16 15:49:25
我正在尝试创建一个存在验证错误的登录页面。现在,如果输入字段不可见,也会出现验证错误。当输入字段不可见时,如何隐藏错误标签?如下图: PIN 输入字段在登录页面上不可见,但错误消息:Pin is required,突出显示。请问有人可以建议一个解决方法吗?
查看完整描述

1 回答

?
米琪卡哇伊

TA贡献1998条经验 获得超6个赞

您可以使用数据绑定将IsVisibleof 标签绑定到视图模型中的属性。


<Label Text="Pin is required!"  TextColor="Red"  HorizontalTextAlignment="Center" IsVisible="{Binding isVisible}"/>


<Button Text="sign in" BackgroundColor="Red" TextColor="White" Command="{Binding ClickCommand}"  WidthRequest="200" />

在你的视图模型中

public class YourViewModel: INotifyPropertyChanged

{

    public event PropertyChangedEventHandler PropertyChanged;


    protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

    {

        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    }


    public ICammand ClickCommand {get; set;}



    private bool isvisible;


    public bool isVisible

    {

     get

     {

        return isvisible;

     }


     set

     {

      if (isvisible!= value)

      {

        isvisible= value;

        NotifyPropertyChanged();

      }

    }



    public YourViewModel()

    {

        //... 

        isVisible = true; //show the label in default

         

        ClickCommand = new Command(() =>

        {

           if(xxx)

           {

              isVisible =false;

           }

           

           else

           { 

              isVisible =true;

           }

        }) ;


    }


}


查看完整回答
反对 回复 2023-09-16
  • 1 回答
  • 0 关注
  • 42 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信