Hi
I use a xamDataGrid. I set AutoFit=true and and AllowResize=true on some FieldSettings. Around my Grid I placed a ScrollViewer. MinWidth of the Grid is set to its initial value.
At first everything seems fine. If I decrease the size of my window (which contains the grid) the scrollbar appears. Then if I increase the size of the window the grid and its columns stretches as expected. So far so good.
However, if I increase the size first the grid stretches as expected but then if I decrease the size the scrollbar appears. I would like to have the grid shrinking until it reaches its MinWidth before the scrollbar would appear... Can I do that?
Hi Dunken,
In my suggestion the XamDataGrid is not inside a ScrollViewer and the scroll bar does appear when the MinWidths are reached. I have uploaded a video (autofit5.zip) of this code in action:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igDP="http://infragistics.com/DataPresenter"
Title="MainWindow" Height="335" Width="403">
<Grid>
<igDP:XamDataGrid BindToSampleData="True" AutoFit="True" >
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings LabelMinWidth="50" />
</igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>
</Grid>
</Window>
Please let us know if there is anything else we can do for you regarding this matter.
Dunken said: I just change the grid as you suggested (AutoFit=false and Field’s-With=Auto). It basically works but unfortunately it doesn’t use the space initially available. Is it possible to set the Field’s width AND a MinWidth?
Normal 0 21 false false false DE-CH X-NONE X-NONE MicrosoftInternetExplorer4
Andrew, thank you for your explanation. I wasn’t aware of the virtualization issue. However, as the number of records and fields in this particular grid will remain low it won’t be too big of an issue (I have to check on other places we use xamDataGrid though).
I just change the grid as you suggested (AutoFit=false and Field’s-With=Auto). It basically works but unfortunately it doesn’t use the space initially available. Is it possible to set the Field’s width AND a MinWidth?
AutoFit doesn't really make sense if the control is within a ScrollViewer. AutoFit is meant to have the grid resize the columns to fill the available area. However when you have the grid within ScrollViewer it is measured with an infinite width so there really is no finite available area. If you are going to put the grid into a ScrollViewer and you want the control to size based on the size of the column widths then it might be best to leave AutoFit set to false and set the FieldSettings->Width to Auto - to have each field autosize to its contents.
I would caution you though about putting a control like xamDataGrid within a ScrollViewer. Since the ScrollViewer is going to measure with an infinite size virtualization cannot be supported (since virtualization requires be measured and arranged based on the the actual available size and not an infinite size - this would be no different than any virtualizing control such as a listbox with a virtualizingstackpanel). So if the HorizontalScrollBarVisibility is something other than Disabled then pretty much every cell in each row that is displayed will be hydrated - i.e. no cell virtualization) and if the VerticalScrollBarVisibility is something other than disabled then every recordpresenter will be hydrated. This isn't entirely accurate as the control will use the lesser of the available size and the sizes provided by the GridViewSettings->(Height|Width)InInfiniteContainers.
Thank you, Petar. I appreciate that.
Unfortunaltey I doesn't work as expected. If I follow your tip no Scrollbar ever appears... Instaed, if start shrinking my grid part of it disappears (although I think it's probably better then the solution I had before).
I have to mention that the xamDataGrid is part of a nested control. The container control is a grid in which I'm using a grid-splitter... Could that have an influence?
Thank you!