Verical scroll while grouping

May 28, 2009 at 3:25 PM

Hi all,

I have a problem with the vertical scroll when the row grouping is active on my data grid. If grouping is active then the vertical scroll does not work right . If a I disable grouping then all works fine. Here are the style for may grid and the grouping style:

<Style x:Key="GridStyle" TargetType="{x:Type dg:DataGrid}">

    <Setter Property="VerticalGridLinesBrush" Value="{StaticResource GridLineColorBrush}" />

    <Setter Property="BorderThickness" Value="1" />

    <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" />

    <Setter Property="Template">

      <Setter.Value>

        <ControlTemplate TargetType="{x:Type dg:DataGrid}">

          <Border                                                 

                       Background="{TemplateBinding Background}"

                       BorderBrush="{TemplateBinding BorderBrush}"

                       BorderThickness="{TemplateBinding BorderThickness}"

                       SnapsToDevicePixels="True"

                       Padding="{TemplateBinding Padding}">

            <ScrollViewer Focusable="false" OverridesDefaultStyle="True">

              <ScrollViewer.Template>

                <ControlTemplate TargetType="{x:Type ScrollViewer}">

                  <Grid>

                    <Grid.RowDefinitions>

                      <RowDefinition Height="Auto"/>

                      <RowDefinition Height="*"/>

                      <RowDefinition Height="Auto"/>

                    </Grid.RowDefinitions>

 

                    <Grid.ColumnDefinitions>

                      <ColumnDefinition Width="Auto"/>

                      <ColumnDefinition Width="*"/>

                      <ColumnDefinition Width="Auto"/>

                    </Grid.ColumnDefinitions>

 

                   

                    <Button

                                                                                                                                    Command="{x:Static dg:DataGrid.SelectAllCommand}"

                                                                                                                                    Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=CellsPanelHorizontalOffset}"

                                                                                                                                    Focusable="false"

                                                                                                                                    Visibility="Visible" />

                    <!--Column Headers-->

                    <dg:DataGridColumnHeadersPresenter

                                                                                                                                    Grid.Column="1"

                                                                                                                                    Name="PART_ColumnHeadersPresenter"

                                                                                                                                    Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=HeadersVisibility, Converter={x:Static dg:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static dg:DataGridHeadersVisibility.Column}}"/>

 

                    <!--DataGrid content-->

                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Grid.Row="1" Grid.ColumnSpan="2" CanContentScroll="True" />

 

                    <ScrollBar Name="PART_VerticalScrollBar"

                      Style="{StaticResource BarStyle}"

                                                                                                                                    Grid.Row="0" Grid.RowSpan="2" Grid.Column="2"

                                                                                                                                    Orientation="Vertical"

                                                                                                                                    Maximum="{TemplateBinding ScrollableHeight}"

                                                                                                                                    ViewportSize="{TemplateBinding ViewportHeight}"

                                                                                                                                    Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"

                                                                                                                                    Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>

 

                    <Grid Grid.Row="2" Grid.Column="1">

                      <Grid.ColumnDefinitions>

                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type dg:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>

                        <ColumnDefinition Width="*"/>

                      </Grid.ColumnDefinitions>

                      <ScrollBar Name="PART_HorizontalScrollBar"

                        Style="{StaticResource BarStyle}"

                                                                                                                                                Grid.Column="1"

                                                                                                                                                Orientation="Horizontal"

                                                                                                                                                Maximum="{TemplateBinding ScrollableWidth}"

                                                                                                                                                ViewportSize="{TemplateBinding ViewportWidth}"

                                                                                                                                                Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"

                                                                                                                                                Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

                    </Grid>

                  </Grid>

                </ControlTemplate>               

              </ScrollViewer.Template>

              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

            </ScrollViewer>

          </Border>

        </ControlTemplate>       

      </Setter.Value>

    </Setter>

</Style>

 

and the grop style:

 

                    <dg:DataGrid.GroupStyle>

                    <GroupStyle>

                      <GroupStyle.Panel>

                        <ItemsPanelTemplate>                         

                          <dg:DataGridRowsPresenter/>                         

                        </ItemsPanelTemplate>

                      </GroupStyle.Panel>

                      <GroupStyle.HeaderTemplate>

                        <DataTemplate>

                          <StackPanel >

                            <TextBlock Text="{Binding Path=Name}" Foreground="White"  FontWeight="Bold" Background="#9492D3" Padding="3"/>

                          </StackPanel>

                        </DataTemplate>

                      </GroupStyle.HeaderTemplate>                     

                    </GroupStyle>

                  </dg:DataGrid.GroupStyle>

               

Does anybody know how to fix that?

 

May 28, 2009 at 3:45 PM

Right,

I found the answer just after posting this, but I still can explain why. The solution is to set  ScrollContentPresenter CanContentScroll to False.