howto fit window's size to datagrid size

Feb 2, 2009 at 10:13 AM
Hi guys,

I've just found WPF Toolkit and it looks very cool, but I have a problem I don't know how to solve it.

I'd like to create a window which contains only the datagrid and the window fits horizontally and vertically to the grid.
How can I achieve this?

Feb 2, 2009 at 10:19 AM
Usually a window's content root element is a <Grid>, did you try simply replacing that with your <DataGrid>?

Alternatively, you can set <DataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">.

The Window also has a SizeToContent property that you might find useful.
Feb 2, 2009 at 12:03 PM

the this.SizeToContent = SizeToContent.WidthAndHeight;

solved my problem, thank you :)