In WPF Stretch a control to fill a ListView Column

前端 未结 3 1813

How do I make a control fill the whole cell in a ListView (with a GridView)? I\'ve played around with various properties, but the control is always it\'s minimum size.

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 04:57

    Another almost-solution is to do something as follows in your datatemplate that goes into the gridviewcolumn

    Width="{Binding  RelativeSource={RelativeSource Mode=FindAncestor , AncestorType=ListViewItem, AncestorLevel=1},Path=ActualWidth}">
    

    This results in it stretching the textbox to the width of the column, but the right edge is clipped and not rendered. I haven't fixed that part yet. So the already accepted answer is still probably the best one.

    Here's a sample DataTemplate which does this.

    
    
    
    

提交回复
热议问题