How to bind DataGridTemplateColumn.Visibility to a property outside of DataGrid.ItemsSource?

前端 未结 2 572
旧巷少年郎
旧巷少年郎 2021-01-11 09:13

I need to bind the Visibility of a DataGridTemplateColumn to a property outside of the DataGrid.ItemsSource,because i need to bind thi

2条回答
  •  余生分开走
    2021-01-11 09:57

    Add this setter in the DataGridTemplateColumn.CellStyle and done:

       
    

    If you need more help look at my example below. I want the Remove button to not be visible at the project level. First you have to make sure you have a isVisible property in your view model:

      private System.Windows.Visibility _isVisible;
        public System.Windows.Visibility isVisible
        {
            get { return _isVisible; }
            set
            {
                if (_isVisible != value)
                {
                    _isVisible = value;
                    OnPropertyChanged("isVisible");
                }
            }
        }
    

    Then:

      if (isProj == false)
                this.model.isVisible = Visibility.Visible;
            else
                this.model.isVisible = Visibility.Collapsed;
    

    XAML:

    
           
                
                   
             
       
       
            
       
    

提交回复
热议问题