Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1280
Window Autosize with XamGrid
posted

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!

Parents
No Data
Reply
  • 6365
    Offline posted

    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.

    XamGrid_sample.zip
Children