Text: The MVVM example of the "C#/WPF" ListView, and disable dragging of the header header of the ListView
A simple example of a ListView's MVVM:
<ListView ItemsSource="{Binding goodslist}" Margin="0,10,0,10" > <listview.view> <GridView> <gridviewcolumn Header="package number" Width="+" displaymemberbinding="{Binding Packageno}" /> <gridviewcolumn Header="Quantity" Width="+" displaymemberbinding="{Binding num}" /> <gridviewcolumn Header="Unit Price" Width="+" displaymemberbinding="{Binding price}" /> <gridviewcolumn Header="Total amount" Width="+" displaymemberbinding="{Binding totalamount}" /> <gridviewcolumn Header="select" Width="+"> <!--can define a template for a cell-- <gridviewcolumn.celltemplate> <DataTemplate> <!--<textblock text= "{Binding Mail}" textdecorations= "Underline" foreground= "Blue" cursor= "Hand"/>-- > <RadioButton GroupName="Package" Checked="radiobutton_checked" /> </DataTemplate> </gridviewcolumn.celltemplate> </gridviewcolumn> </GridView> </listview.view></ListView>
The post-run effect is as follows (not populated with any entries):
Problem: Users are free to drag and drop to change the width of the head! This action needs to be suppressed.
Give < GridView > set its header style to disabled, the code is as follows:
<GridView.ColumnHeaderContainerStyle> <Style TargetType="{x:Type GridViewColumnHeader}"> <SetterProperty="IsEnabled"Value="False"/> </Style></GridView.ColumnHeaderContainerStyle>
Important References:
(Google search WPF lock ListView Header)
Http://stackoverflow.com/questions/181956/prevent-user-from-resizing-columns-with-wpf-listview
MVVM example of the "C#/WPF" ListView, and Disable dragging of the ListView header header