Binding Visibility Converter in WPF C#

后端 未结 4 1155
醉话见心
醉话见心 2020-12-21 03:03

I have a dependency property of type collection, when its callback fires based on the count I need to set the visibility of some of the controls on the screen.

But t

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 03:29

    You need to notify the change:

    public event PropertyChangedEventHandler PropertyChanged;
    private bool _countLabelVisible = false;
    
    private void RaisePropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    
    
    public bool CountLabelVisible 
    { 
        get
        {
            return _countLabelVisible;
        }
        set
        {
            _countLabelVisible = value;
            RaisePropertyChanged("CountLabelVisible");
        }
    }
    

    The binding "framework" needs to be informed that the binding needs refreshing, which is what the Raise... is about. This is pretty quick and dirty (and untested) but should demonstrate what you need to do.

提交回复
热议问题