RadGridView gets huge for no reason

2 posts, 0 answers
  1. Lukas
    Lukas avatar
    20 posts
    Member since:
    Jul 2011

    Posted 03 Dec 2012 Link to this post

    Hello Telerik,

    I've got a bit of a fight with your GridView/TreeListView.
    We use your GridView as a search grid, which dynamically resizes, as soon as the user resizes the whole window. The RadGridView is held by a ContentControl.

    Sometimes the Grid appears far too wide. We couldn't figure out whether it depends on the data or the Xaml (maybe something else?). Yes, I know it's better if you use the RadGrid with fixed height and width for performance, but the requirement, that the grid resizes with the application size, must be met. Since there isn't that much data shown in our grids (10-20 rows max), we really don't need the performance boost of virtualization.

    I debugged the construction of the visual tree and every control measures alright, except the RadGridView. I read a lot in your documentation, where was told, that measuring the RadGridView with double.PositiveInfinity might cause performance issues, but it should be possible, shouldn't it? However, the RadGridView is measured with double.PositiveInfinity either ways and returns a DesiredSize.Width of 60.000 pixles. How is this possible? And the GridView is shown really, really buggy. It's split in a couple of parts in horizontal direction. Firstly theres a Grid, which contains all its columns. Then about a 1000 pixles margin, then an empty Grid, which is huge, space again and finally another empty Grid. All of them contain the right amount of rows, though.

    Here's code of a Grid, which is shown wrong sometimes.

    <Grid Grid.Row="1"
          Grid.ColumnSpan="3"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <telerik:RadGridView x:Name="SearchGrid"
                         Grid.Row="0"
                         AlternateRowBackground="{StaticResource B4Brush}"
                         AlternationCount="2"
                         AutoGenerateColumns="False"
                         BorderBrush="#FF848484"
                         BorderThickness="1,0"
                         CanUserFreezeColumns="False"
                         ColumnReordered="SearchGrid_ColumnReordered"
                         ColumnWidthChanged="SearchGrid_ColumnWidthChanged"
                         IsFilteringAllowed="False"
                         IsReadOnly="True"
                         ItemsSource="{Binding SearchManager.FoundItems}"
                         RowIndicatorVisibility="Collapsed"
                         RowLoaded="SearchGrid_RowLoaded"
                         SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                         SelectionMode="Single"
                         ShowGroupPanel="False"
                         Sorting="SearchGrid_Sorting"
                         VerticalGridLinesBrush="{x:Null}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Width="5*"
                                     DataMemberBinding="{Binding}"
                                     Header="Termin">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0 8">
                                <TextBlock FontWeight="Bold"
                                     Foreground="{Binding TitelFarbe, Mode=TwoWay}"
                                     Text="{Binding SearchItemMasterEntity.FieldArr[0]}" />
                                <TextBlock MaxHeight="{Binding DataContext.MaxTextHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadTreeListView}}"
                                     Text="{Binding SearchItemMasterEntity.FieldArr[1]}"
                                     TextWrapping="Wrap" />
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="RowActivated">
                        <cal:ActionMessage MethodName="DoEdit" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
     
            </telerik:RadGridView>
     
               <Button x:Name="SearchMore"
                Grid.Row="1"
                Margin="5"
                HorizontalAlignment="Left"
                Content="{Binding TL[SearchControl.More]}" />
            <TextBox x:Name="TextBoxResultNumbers"
                 Grid.Row="1"
                 MinWidth="50"
                 Margin="0,5,5,5"
                 HorizontalAlignment="Right"
                 IsReadOnly="True"
                 Text="{Binding SearchManager.SearchResultNumbers}" />
        </Grid>
    </Grid>


    I'd really like to reproduce the issue in a sample project, but I can't figure out how. I appreciate every advice of you, which might solve this problem.

    Kind regards

    edit: I found out something else, which seems pretty strange to me. If I start the application in OOB mode, the RadGridViews usually show up the right way. But if I start the app in the browser almost every Grid gets measured huge. Might this be caused by a ScrollViewer? I think the browser window is just a big ScrollViewer, isn't it?

    edit2: another update. When I remove every ScrollViewer in our visual tree, the RadGridViews are really just as big as their parent is. But as soon as I reactivate the ScrollViewer, the Grids get huge again. Do you know what causes this?
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 04 Dec 2012 Link to this post

    Hello,

     Your requirement to resize RadGridView with the parent container can be met if you use Grid layout. Using components like ScrollViewer, StackPanel, Canvas, etc. cannot fit in such scenario since they will measure all child controls with infinity height and width.

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top