The ListView is defined in the XAML part.
<ListView x:Name="MyListView"> <!-- ... --> <ListView.ContextMenu>
In the constructor of the code-behind part the event handler is added.
ResultDataView.AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler(Thumb_DragDelta), true);
The event handler takes care that column width is not set under 20 (in this example).
private void Thumb_DragDelta(object sender, DragDeltaEventArgs e) { Thumb senderAsThumb = e.OriginalSource as Thumb; GridViewColumnHeader header = senderAsThumb.TemplatedParent as GridViewColumnHeader; if (header == null) { return; } if (header.Column.ActualWidth < 20) { header.Column.Width = 20; } }
Thank you for this blog post. It was able to solve my issues quickly and cleaner than any other working solution that I have found.
ReplyDelete