Hello everybody,
I have the feeling that this is a very basic and stupid question, but I am having hard time anyway... so
I have a window hosting a XamGrid. I am setting the columns. This is the very simple declaration
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False" ItemsSource="{Binding Path=Properties_w}" ColumnWidth="Auto"><ig:XamGrid.ColumnResizingSettings><ig:ColumnResizingSettings AllowCellAreaResizing="True" AllowColumnResizing="Disabled"/></ig:XamGrid.ColumnResizingSettings><ig:XamGrid.Columns><ig:TextColumn Key="PropertyName" HeaderText="{locExt:Localizer prop}"/><ig:TextColumn Key="Category" HeaderText="{locExt:Localizer category}"/><ig:TextColumn Key="SubscribedTo" /><ig:TextColumn Key="DataType" /><ig:TextColumn Key="Units" /><ig:TextColumn Key="UserAccess" /><ig:TextColumn Key="ConstraintStatus" Width="*"/></ig:XamGrid.Columns></ig:XamGrid>
As you can see, I set Auto for every column's width, except for the last one (*) which will take all available space.
I simply want my window to adapt to the width of the grid.
How can i do that? If I set Width="Auto" the window will (don't know why) grow more than necessary. If I set a constant number (e.g. Width="500") the window won;t resize (scrollbars will appear). If I set SizeToContent="Width" the window will grow, grow grow...
Why is that so hard:? What am I missing?
The window will simply host this grid and I want it to have the proper size
PS: I am using XamGrid, but if you have a suggestion for XamDataGrid I can use it, no problem
Thanks in advance!
Hello Valentina,
Thank you for the code-snippet you have provided.
The behavior you have described in regards to all columns being with an auto width except for the last one (which takes up all the remaining space) seems to be working as expected. (refer to 2 in the grids.png image inside the zip) In this case, when resizing the window, the width of the last column gets smaller as well.
In order for all columns to have the same width at all time by taking up all of the window's space and dividing it equally, you can set the ColumnWidth property of the XamGrid to * (analogically in the XamDataGrid, you can set the AutoFit property to True). (refer to 3 in the grids.png image inside the zip)
I have attached a sample application that uses the approaches from above.
If you have any questions, please let me know.
Thanks Tacho for your feedback.
However, I am afraid I was not clear in my question
What I am trying to achieve is: is there a way to make the Window resize according to Grid content?
I can see from your xaml that you have set for the window: Height="600" Width="800". This way, the window will have 800 as width, and the grid will resize accordingly (with *, all columns will have same width).
I mean, all I want is exactly the other way around: I want all columns to have “Auto” width (according to their header/cell size), and the window must resize accordingly. Is there a way to do that?
PS: I couldn't find any images in the zip
Thanks again
Valentina