WPF Trigger binding to MVVM property

前端 未结 4 880
误落风尘
误落风尘 2020-12-31 11:10

I have a datatemplate containing an image that I want to be hidden if the the value of a property in a ViewModel is true. Can anyone tell me why the the xaml below does not

4条回答
  •  被撕碎了的回忆
    2020-12-31 11:57

    In my opinion we not need to use Triggers, with only the Binding it works well. To make binding to a property model, you can use BooleanToVisibilityConverter Is declared as follows:

    
        
    
    

    And how to use it is simple, just point to the key stated above:

    
    

    The property in the ViewModel:

    private bool _hasError = false;
        public bool HasError
        {
            get { return !string.IsNullOrEmpty(_messageError); }
            set 
            {
                _hasError = value;                
                this.NotifyOfPropertyChange(() => this.HasError);
            }
        }
    

提交回复
热议问题