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

后端 未结 5 958
无人共我
无人共我 2021-02-13 02:08

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


    
        

        
5条回答
  •  [愿得一人]
    2021-02-13 02:24

    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;   
     }
    }
    }
    

提交回复
热议问题