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
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
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" >
<ItemsPanelTemplate>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid>
</igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate>
</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.
Try setting the Field.Settings.CellHeight, or CellMaxHeight property instead, that won't affect the header area.
My latest posting is still awaiting approval, but here's another comment anyway:
I solved the problem for now by applying a rather ugly hack: I defined a style for the XamTextEditor, which restricts the maximum height for the editor. Like this, the row doesn't resize itself in case of multiline text:
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igEditors:XamTextEditor}"> <Setter Property="MaxHeight" Value="22" /> </Style> </igDP:XamDataGrid.Resources>
Joe,
Me again, sorry. I ran into a new issue with the auto-sizing of the grid. I have a field that may provide multi-line text (a lot of). This wasn't a problem until now - the grid just cropped the content, which could be edited through a popup:
However, by assigning a template for the grid, the row's height adjusts to it's content - which is bad if the underlying text consinsts of 50+ lines of text of course. I tried to solve the problem by assigning a RowDefinition for the grid. However, it appears this also affects the header area, which gets badly cropped:
<igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="30" /> <ColumnDefinition Width="150" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="4*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="24" /> </Grid.RowDefinitions> </Grid> </ItemsPanelTemplate></igDP:FieldLayoutSettings.DataRecordCellAreaGridTemplate>
Is there a way to get all of this working at the same time?
- auto-sizing- no resizing of the row height (optimum) or fixed row height- independent row height of the header
Edit:
However, a cleaner solution would be welcome.
Cheers,
Philipp