C#/WPF: Make a GridViewColumn Visible=false?

后端 未结 5 664
北恋
北恋 2021-02-13 02:15

Does anyone know if there is an option to hide a GridViewColumn somehow like this:


    
        

        
5条回答
  •  再見小時候
    2021-02-13 02:41

    Use if Thumb.DragDelta may solve the problem

    I use it in listview as

    
    
    
    public Window1()
    {   
    InitializeComponent(); 
    MyListView.AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(Thumb_DragDelta), true );
    
    void Thumb_DragDelta(object sender, DragDeltaEventArgs e)
    {  
     Thumb senderAsThumb = e.OriginalSource as Thumb;    
     GridViewColumnHeader header = senderAsThumb.TemplatedParent as GridViewColumnHeader;     
     if (header.Column.ActualWidth < MIN_WIDTH)   
     {   
        header.Column.Width = MIN_WIDTH;  
     }  
     if (header.Column.ActualWidth > MAX_WIDTH)     
     {      
        header.Column.Width = MAX_WIDTH;   
     }
    }
    }
    

提交回复
热议问题