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
  • 975
    posted

    Hello,

    I raised a similar question about this several years ago, I can't find the link now. But basically the xamGrid is designed to behave like the following:

    1) The xamGrid will stretch to fill the entire available space provided to it

    2) If the available space is Infinity then it will size to fit (fully render its content)

    So since your xamGrid is placed in a window with no max sizes specified, the available size of the window will be the size of your screen/monitor (not infinity). This is the available size that is passed to the xamGrid for rendering and the xamGrid will stretch to fill this available space. 

    If you instead place your xamGrid inside of a scrollviewer within the window, then the available space passed into the xamGrid will be Infinity. In this case the xamGrid will render all of it's content and size itself accordingly. This might fix your problem if you don't have very many columns, however when using a scrollviewer you force the xamGrid to fully render it's contents and thus loses all virtualization functionality and could have a large performance impact.

    I don't like the way it works, but this is how the xamGrid is designed to behave, as far as I can tell through different tests.

    -Chris

Children
No Data