Force resize of GridView columns inside ListView

后端 未结 5 1743
Happy的楠姐
Happy的楠姐 2020-12-10 02:07

I have a ListView WPF control with a GridView. I\'d like to resize the GridView columns when the content of the columns changes.

5条回答
  •  自闭症患者
    2020-12-10 02:48

    If like me you are old and prefer VB.NET then here's Oskars code:

    Public Sub AutoSizeColumns()
        Dim gv As GridView = TryCast(Me.listview1.View, GridView)
        If gv IsNot Nothing Then
            For Each c As GridViewColumn In gv.Columns
                If Double.IsNaN(c.Width) Then
                    c.Width = c.ActualWidth
                End If
                c.Width = Double.NaN
            Next
        End If
    End Sub
    

    This works great in WPF, finally someone has worked this out. Thanks Oskar.

提交回复
热议问题