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?
Hello Dunken,
I have been looking into your requirement and this is rather expected, since when a control is placed inside a ScrolViewer, there isn’t a boundary that would confine him in any side, but rather the ScrollViewer’s ScrollBars are visualized to enable scrolling through the taken space. Usually the a simple control would not fit the ScrollViewer in the first place as the AutoFitted XamDataGrid does, however the XamDataGrid’ template is quite complex and also contains a ScrollViewer inside itself. This is why in order for you to achieve the desired functionality I can suggest using the built-in ScrollViewer and the supported functionality like so:
<igDP:XamDataGrid BindToSampleData="True" AutoFit="True" >
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings LabelMinWidth="50" />
</igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>
This code will allow the auto-fitting until the Fields reach their minimum widths when the inner HorizontalScrollbar will appear. For this particular snippet the whole MinWidth would sum up to 4x50 for the four Fields + 20 for the RecordSelector element.
Please let me know if I can be of any further assistance on the matter.
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!
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.
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?
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?