Original: [WPF Troubleshooter] How to limit the width of a listview column
How to limit the ListView column width [WPF troubleshooter]
Zhou Banhui
One of the defect that is encountered today is to limit the column width in the list view to prevent the column from dropping by dragging the column width to 0 . The WPF list view does not have this mechanism built in, but we can monitor the user drag and drop to track the width of the column and further limit the user drag, I have already fixed the problem, please see the demo in the attachment.
Demo The "Listviewlayoutmanagerlib" project in the operation has been encapsulated, how to use the package, please refer to the following instructions (or GridViewCodeDemo.Window1.xaml)
1 , introduce listviewlayoutmanagerlib into your project with the name introducing namespaces: Xmlns:listviewmgr= "clr-namespace:listviewlayoutmanagerlib;assembly =listviewlayoutmanagerlib "
2 , enable listviewmanager:listviewmgr:listviewlayoutmanager.enabled= "True" on a ListView control that requires a qualifying operation
3 , set the qualifying value on the column that needs to be listviewmgr:rangecolumn.minwidth= "
<listview listviewmgr:listviewlayoutmanager.enabled= "True">
<listview.view >
<gridview allowscolumnreorder= "true" >
<gridviewcolumn
listviewmgr:rangecolumn.minwidth= "
Header= "MinWidth100"
Width= "/>"
<gridviewcolumn
listviewmgr:rangecolumn.minwidth= "
Listviewmgr:rangecolumn.maxwidth= "200"
Header= "width100~200" width= "/>"
<gridviewcolumn header= "Normal" width= "/>"
</GridView>
</ListView.View>
</ListView>
Demo download
How to limit the ListView column width [WPF troubleshooter]