Bind visibility property to a variable

前端 未结 5 706
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 14:12

I have a Border with Label inside a Window,



        
5条回答
  •  攒了一身酷
    2020-12-05 14:39

    Another solution is to use Trigger Style:

    
        
            
        
        
            
    
    

    In the model class:

    public class ModelClass: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void NotifyPropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
    
        private bool _vis;
        public bool vis
        {
            get => _vis;
            set
            {
                _vis = value;
                NotifyPropertyChanged("vis");
            }
        }
    }
    

    Don't forget to bind DataContext with your model !

    DataContext = new ModelClass();
    

提交回复
热议问题