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!
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>
</Grid>
</Window>
Please let us know if there is anything else we can do for you regarding this matter.