MinWidth for ListView column

How can I specify MinWidthfor a Listview column in WPF?

+3
source share
1 answer

This code uses the Thumb control. This will not allow the user to drag the title only at the specified width.

Add this to your WPF

<ListView x:Name="MyListView"
          IsSynchronizedWithCurrentItem="True" 
          ItemsSource="{Binding Path=Items,  
                                Mode=Default, 
                                Source={StaticResource DataProvider}}"
          Thumb.DragDelta="Thumb_DragDelta">

And in C # do 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;
}
+3
source

Source: https://habr.com/ru/post/1708186/


All Articles