I am attempting to AutoFit my GridView in a DockPanel, which is causing me difficulties. I have not set a height or width, but I have set a minimum and maximum width for when it resizes. My question is what snippet of code is need in order to AutoFit the GridView in a DockPanel.
Thanks in advance,
Chris
4 Answers, 1 is accepted
As I understand your question, you want the GridView to AutoFit the DockPanel.
In order to AutoFit in a container panel, like DockPanel, you should set Width="Auto". This way when you resize the container, the GridView will follow the it, filling it.
If you want your columns' width to resize appropriately to the GridView width, you may use ColumnWidht="*".
<DockPanel Background=
"BlanchedAlmond"
>
<telerik:RadGridView Name=
"playersGrid"
Width=
"Auto"
ColumnWidth=
"*"
>
</telerik:RadGridView>
</DockPanel>
Could you please share with us, if this suggestion is answering your question? Kind regards,
Didie
the Telerik team

This did not solve my issue, so let me try to explain as best as I can. I am using a Telerik GridView control inside of a DockPanel, which is inside of a Grid in Expression Blend 4 (not a telerik grid). All of my content and controls have no issue auto-sizing to the width of the window, as I have set the width and relative margins of all other content areas. But the Telerik GridView only fills up about 1/2 of the width of the screen...when I set the size of the GridView to Width="Auto" or ColumnWidth="*" the GridView does start to take up the remainder of the width...but it does not resize in the relation to the rest of the content when the window is resized. This completely defeats the purpose of trying to autosize based on content. Am I missing something here, or perhaps doing something wrong?
Thanks for your assistance,
Chris
<
DockPanel
x:Name
=
"DockPanel_Row3"
LastChildFill
=
"False"
Margin
=
"5,0,0,0"
VerticalAlignment
=
"Top"
Grid.Row
=
"2"
Grid.ColumnSpan
=
"3"
Grid.Column
=
"0"
MaxWidth
=
"680"
HorizontalAlignment
=
"Left"
MinWidth
=
"446"
Width
=
"Auto"
>
<
telerik:Label
Content
=
"Subcommittee Members"
Height
=
"20"
VerticalAlignment
=
"Top"
HorizontalAlignment
=
"Left"
Padding
=
"0,3,5,3"
DockPanel.Dock
=
"Top"
Margin
=
"0"
HorizontalContentAlignment
=
"Stretch"
VerticalContentAlignment
=
"Stretch"
/>
<
telerik:RadGridView
x:Name
=
"grMembers"
Margin
=
"0"
VerticalAlignment
=
"Top"
Width
=
"Auto"
ColumnWidth
=
"*"
ItemsSource
=
"{Binding MemberList}"
AutoGenerateColumns
=
"True"
VerticalContentAlignment
=
"Stretch"
DockPanel.Dock
=
"Bottom"
HorizontalContentAlignment
=
"Stretch"
MinWidth
=
"446"
MaxWidth
=
"900"
GroupPanelBackground
=
"{DynamicResource GridViewDragHeader}"
BorderBrush
=
"{DynamicResource GridViewDragHeaderStroke}"
/>
</
DockPanel
>
I notice that you add Min and Max Width and then AutoSize to the DockPanel and the GridView. This means that the controls will AutoSize between the MInWidth and the MaxWidth only. You set MaxWidth of the GridView="900", but the maximum that it may go is the MaxWidth="680" of the DockPanel.
I have captured a video that tries to reproduce the behavior that you reference. Could you please review it and confirm is this the case?
I have prepared a sample project, showing how the GridView is auto fitting the window resize right, when the Min and MaxWidth is removed. If you prefer to keep the Min and Max width, then they need to correspond to the Min and Max width of the Window, so that when Window resizes, the DockPanel/GridView could resize appropriately.
Could you please review the sample project and let me know if this is solving your auto fitting problem?
Didie
the Telerik team

Edit: Rather than using the MinWidth property I used the * in the column width property ie.. width="100*"