OK, I'm having a heck of a time trying to find the magic incantations to make columns automatically size to their content.
Suppose I have three columns: "Size", "Mean" and "Sample Standard Deviation". I would like the Size and Mean columns to squeeze down to some minimum width, say 75 WPF pixels. But I would like the third column to expand to show the full text of the label.
"Autofit"only seems to make all columns the same width, which is not what I want.
As a bonus, I would also like to have each column automatically size to its data, so that if I entered "9999999999" in the size column, then the whole column would automatically grow larger to accommodate the new number.
Thanks,
Denny Huber
In order to do this you also have to specify a template for the grid that will be used to layout the cells in each record, as in the sample xaml below.
Note: The reason we had to take this approach instead of hanging properties off the Field is because in more complex cell layout scenarios, e.g. where cells span mutiple row/columns within each record there is not a one for one correspondence between the Field and the column(s) that contain it within the cell area of a record.
<igDP:FieldLayoutSettings>
<igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate>
</igDP:FieldLayoutSettings>
</igDP:XamDataPresenter.FieldLayoutSettings>
So far so good, but this makes a *very* common scenario rather complex, and if I got that right, it disallows the user to resize the column widths. My current project contains roughly 10 different grids and I'm missing a working resizing behaviour in every one of them, mainly because I want to fill the columns all available space (AutoFit is a joke, I really can't image I'll ever need equally sized columns in a real live application that provides heterogenous data). IMO there is no valid explanation why this shouldn't work like WinGrid - if AutoFit AND cell widths would work together, we had a simple solution.
Just my 0.02$
BTW - I tried to apply a template to a very simple dialog grid, but with mixed results. What I would like to get is a grid that expands the last column to the full size of the grid. Here's the results:
First I tried the star sized last column according to Joe's sample - bad result, text is being cropped, and the other columns are far too wide:
Second try: Setting fixed widths and Auto on the last column. This appears right, but it isn't, as text gets cropped as well - The full string is longer than just "Invariant Language".
Finally, I tried combinding fixed widths with a star-sized column - again, text is being cropped:
Is there a combination I overlooked (also tried not setting a width for the last column at all, same result as the last image)?
Thanks for your advice
Philipp
If you use '*' columns then in this scenario you have to set the XamDataGrid's AutoFit property to true. If that property is set to true and you are still having a problem then it sounds like a bug.
Joe,
Great, that fixed it! And best of all: even column resizing still works that way in the Beta.
Thanks for your help!
Phil,
I wonder if I could bother you to send me the ItemsPanelTemplate you are using that has column resizing working. I have done the following and resizing does not work.
<igDP:XamDataGrid x:Name="_dataGrid" DataSource="{Binding StoryList}" AutoFit="True" GroupByAreaLocation="None" >
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" SelectionTypeRecord="Single" RecordSelectorLocation="None" >
<ColumnDefinition Width="*" />
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayout>
<igDP:FieldLayout.FieldSettings>
</igDP:FieldLayout.FieldSettings>
<igDP:Field Name="Title" Label="Story Title"/>
</igDP:FieldLayout.Fields>
</igDP:XamDataGrid.FieldLayouts>
The underlying data is simply a class with two properties of type string.
Hi John
I assume your layout isn't resizable, because you only have two columns, and one of them has a fixed width (100px). This one, for example, works fine:
<ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="30" /> <ColumnDefinition Width="150" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="4*" /> </Grid.ColumnDefinitions> </Grid></ItemsPanelTemplate>
HTH,Philipp