Silverlight - DataGrid in Scrollviewer, Column.Width=“*” makes datagrid take several screen-widths

后端 未结 2 1299
野趣味
野趣味 2021-01-19 11:08

When I have the following setup, the last column having a width of * causes the datagrid to create huge horizontal scrollbars (extends grid to several widths of the screen).

相关标签:
2条回答
  • 2021-01-19 11:25

    If you remove

    dg.Columns[2].Width = new DataGridLength(1, DataGridLengthUnitType.Star);

    the problem should go away. Can I ask why you want the last column to take the rest of the space? The column actually knows to resize itself properly to fit its cell size and column header size.

    Also, if you don't specify the column's width, then you don't really need a scrollviewer to scroll and see all the columns. The datagrid has a scrollviewer built in and when there are columns out of the screen the horizontal scrollbar will apear.

    I hope this helps. :)

    0 讨论(0)
  • 2021-01-19 11:29

    you need to put a maxwidth on the scrollviewer? otherwise width is defaulted to auto and maxwidth is infinity

    0 讨论(0)
提交回复
热议问题