How to hide the error label in Xamarin forms, when the Entry field is not visible?

前端 未结 1 1676
南方客
南方客 2021-01-27 11:01

I am trying to create a Login page that has validation errors. Right now the validation errors are also appearing if the Entry field is not visible. How would I hide the error l

1条回答
  •  走了就别回头了
    2021-01-27 11:38

    Agree with Jason . You can use the data-binding to binding the IsVisible of labelto the property in your viewmodel .

    in your ViewModel

    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;
               }
            }) ;
    
        }
    
    }
    
    

    0 讨论(0)
提交回复
热议问题