How do I get a grid to auto size?
Want it to be as small as possible but still show all the columns.
Also if I add a column i want it to resize.
On a similar note whenever i try to open a xaml file that contains a infragistics control, in blend i get an exception. Do i need to load something in blend to prevent this?
thanks
Hi,
So i'm not completely sure what you're looking for.
If you're looking for all columns to always be visible, no matter what size the grid is, then you should set the ColumnWidth property to "*";
<ig:XamWebGrid ColumnWidth="*"/>
If you're looking for the grid to size dynamically, based on the size of it's content, then you shouldn't set a width on the grid, and you need to put it in a panel, that would give it infinite width, such as StackPanel with it's orientation set to Horizontal. (Note this will disable star sizing, and horizontal cell virtualization)
-SteveZ
I want it to be as small as possible but still show all the columns.
So if i have a table that has 3 columns:
ColumnA,ColumnB,Column C
I want the grid to only be as wide as those columns and no wider. I am getting a large space to right of the last column.
Also if I dynamically add another column i want it to dynamically get bigger.
Putting it into a stack panel with orientation horizontal seems to do the trick.
Only now i have a different issue. When I add columns and it get too big, it just gets cut off to the right, with out the scroll bar popping up.
How do i get the scroll bar to show up once it get too big?
So, unfortunately there isn't really a way to do that in Silverlight.
If a control is in a container that gives it a width, the control will size to that width, not to its content, and if its container gives it infinite width, it sizes to its content, which however means it won't have a scrollbar, as its being told to render everything.
So, what the xamWebGrid does, is when its given a width, it renders all its columns, based on the columnwidth, and then with the additional space it renders, what we call a FillerColumn.
I suppose, you could probably change the style of the FillerColumn to be basically transparent, and then remove the border around the grid. However, the grid would still be taking up that space.
Would that satisfy your needs?
To be more clear, what i am trying to obtain is:
A grid that resizes to width of all its columns. Unless it gets bigger than the page. It thens uses a scroll bar.
I don't think putting a scroll view in a stack panel will work because i have cells on the left of the grid that are frozen so the scroll bar must be on the grid.
thanks for all your help so far.
So, once you give the grid Infinite width, its impossible to have the xamWebGrid display a horizontal scrollbar, b/c at that point it doesn't know how wide it should and when it should be displaying it. So, for that scenario, you should wrap the StackPanel in a ScrollViewer.