Binding Visibility Converter in WPF C#

后端 未结 4 795
囚心锁ツ
囚心锁ツ 2020-12-21 02:39

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:25

    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.

提交回复
热议问题