DataGrid-Column widths not updating on ItemsSource change

后端 未结 4 727
执笔经年
执笔经年 2020-12-19 16:43

XAML:


    

        
4条回答
  •  抹茶落季
    2020-12-19 17:12

    Maybe I can help. I had the same problem and I found, I think, nice solution.

    private void DataGrid_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            DataGrid dg = (DataGrid)sender;
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                double width = 0;
                foreach (DataGridColumn column in dg.Columns)
                {
                    width += column.ActualWidth;
                }
                dg.Width = width + 2;
            }
        }
    

提交回复
热议问题