Scrolling in a grouped list

I am so desperate ... to get a list of my WPF lists ... I can't scroll in my list ...

In my sample application, I have a Listview with two extensions. The first one contains a lot of listviewitems ... so you need to scroll ... But if I use the “damned scrollbar”, it goes directly to the next expander (in my case, the 2of2 expander) ... so it's impossible to scroll correctly ...

First screenshot: View 1

Second screenshot: View 2

My ListView style:

<Style x:Key="list12" TargetType="ListView"> <Setter Property="SnapsToDevicePixels" Value="true"/> <Setter Property="OverridesDefaultStyle" Value="true"/> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListView"> <Border Name="Border" BorderThickness="1" BorderBrush="#999999" Background="#DFDFDF"> <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}"> <ItemsPresenter /> </ScrollViewer> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> 

My GridView.GridViewScrollViewerStyle:

 <Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="ScrollViewer"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ScrollViewer"> <Grid Background="{TemplateBinding Background}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <DockPanel Margin="{TemplateBinding Padding}"> <ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Focusable="false"> <GridViewHeaderRowPresenter Margin="0,0,0,0" Columns="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContainerStyle="{Binding Path=TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate,RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}" ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </ScrollViewer> <ScrollContentPresenter Name="PART_ScrollContentPresenter" KeyboardNavigation.DirectionalNavigation="Local" CanContentScroll="True" CanHorizontallyScroll="False" CanVerticallyScroll="False"/> </DockPanel> <ScrollBar Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Maximum="{TemplateBinding ScrollableWidth}" ViewportSize="{TemplateBinding ViewportWidth}" Value="{TemplateBinding HorizontalOffset}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/> <ScrollBar Name="PART_VerticalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" ViewportSize="{TemplateBinding ViewportHeight}" Value="{TemplateBinding VerticalOffset}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 

My ListViewItemContainerStyle:

 <Style x:Key="ListViewItemContainerStyle" TargetType="{x:Type ListViewItem}"> <Setter Property="Background" Value="#ffffff" /> <Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Foreground" Value="Black" /> <Setter Property="Margin" Value="0,0,0,0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Border x:Name="Bd" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" BorderThickness="0,0,0,1" BorderBrush="#6FBDE8"> <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter TargetName="Bd" Property="BorderBrush" Value="#FF143c65" /> <Setter Property="Background" TargetName="Bd"> <Setter.Value> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#FF75aac7" Offset="0"/> <GradientStop Color="#FF143c65" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Bd" Property="Background" Value="#e0eff8" /> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true" /> <Condition Property="Selector.IsSelectionActive" Value="True" /> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="Bd"> <Setter.Value> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#FF75aac7" Offset="0"/> <GradientStop Color="#FF143c65" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> <Setter Property="BorderBrush" TargetName="Bd" Value="#FF143c65"/> <Setter Property="Foreground" Value="White"/> </MultiTrigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> 

Only my list:

 <ListView Style="{StaticResource list12}" Name="ListView1" ItemsSource="{Binding}" ItemContainerStyle="{DynamicResource ListViewItemContainerStyle}" Margin="0,44,0,0"> <ListView.GroupStyle> <GroupStyle> <GroupStyle.ContainerStyle> <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template" > <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <Expander IsExpanded="true" BorderThickness="0,0,0,1" Margin="10"> <Expander.Header> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="10"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Label Content="{Binding Path=Name}" Grid.Column="0"/> <Label Content="{Binding Path=ItemCount}" FontWeight="Bold" Grid.Column="2"/> </Grid> </Expander.Header> <Expander.Content> <ItemsPresenter /> </Expander.Content> </Expander> </ControlTemplate> </Setter.Value> </Setter> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </ListView.GroupStyle> <ListView.View> <GridView> <GridViewColumn CellTemplate="{StaticResource IDItemTemplate}" Header="ID"/> <GridViewColumn CellTemplate="{StaticResource DateItemTemplate}" Header="Datum" /> <GridViewColumn CellTemplate="{StaticResource TypeItemTemplate}" Header="Typ" /> <GridViewColumn CellTemplate="{StaticResource StatusItemTemplate}" Header="Status" /> <GridViewColumn CellTemplate="{StaticResource AuthorItemTemplate}" Header="Autor" /> <GridViewColumn CellTemplate="{StaticResource BenennungItemTemplate}" Header="Benennung" /> </GridView> </ListView.View> </ListView> 

I don’t know how I can solve my problem ... I hope some of you will help me make it work ...

Thank you all for your efforts.

+8
listview wpf grouping scrollbar
source share
1 answer

Your problem is the <Setter Property="ScrollViewer.CanContentScroll" Value="true"/> setter property for the ListView style.

ScrollViewer content can be scrolled in terms of physical units or logical units. Physical units are device independent pixels. Logical units are used to scroll through items in an ItemsControl. (this is what you are doing now) . The default behavior of ScrollViewer is to use physical units to scroll through its contents. However, in cases where the CanContentScroll parameter is set to true, the content may use logical units to scroll. For example, ListBox, ListView, and other controls that inherit from ItemsControl use logical units to scroll. If CanContentScroll is true, the values ​​of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are the number of elements, not physical units.

If you need physical scrolling instead of logical scrolling, wrap the host bar item in ScrollViewer and set the CanContentScroll property to false. Physical scrolling is the default scrolling behavior for most panel elements.

for more information see here: http://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.cancontentscroll.aspx

+10
source share

All Articles