Из-за GroupStyle у ItemsControl скролл работает криво
Есть ItemsControl, который содержит некоторый элементы. Этих элементов может быть много, поэтому добавил ScrollViewer. Теперь появилась необходимость эти элементы группировать по сворачиваемым блокам. При помощи ItemsControl.GroupStyle и Expander я добился сворачиваемых групп, но теперь скролл происходит не как обычно, а по группам.
Например, если на экран влезает 50 элементов, а в какой-нибудь группе их больше, то при попытке скролла происходит "скачок" к следующей группы.
<ItemsControl ItemsSource="{Binding Source={StaticResource GroupedCollectionViewSource}}"
Grid.Row="1"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="0 10 0 0">
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Hidden"
CanContentScroll="True">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
ScrollViewer.IsDeferredScrollingEnabled="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Style="{DynamicResource RdpButton}"
HorizontalContentAlignment="Left"
Click="OpenRdp"
Tag="{Binding Host}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="15"/>
</Grid.ColumnDefinitions>
<Ellipse Grid.Column="0"
Width="10"
Height="10"
VerticalAlignment="Top"
HorizontalAlignment="Center"
Fill="{Binding EllipseColor}"
Margin="0"/>
<StackPanel Grid.Column="1"
Orientation="Vertical"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Margin="0 -3 0 0">
<TextBlock Text="{Binding Name}"
FontWeight="Bold"/>
<TextBlock Text="{Binding Host}"
Margin="0 10 0 0"/>
<TextBlock Text="{Binding Username}"/>
</StackPanel>
</Grid>
<Button.ContextMenu>
<ContextMenu IsEnabled="{Binding IsCustom}"
Visibility="{Binding IsCustom, Converter={dxmvvm:BooleanToVisibilityConverter}}">
<MenuItem Header="Изменить"
Command="{Binding OpenChangeWindowCommand}"/>
<MenuItem Header="Удалить"
Command="{Binding RemoveRdpCommand}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Margin="10 0"
IsExpanded="True">
<Expander.Header>
<TextBlock Text="{Binding Name}"
FontSize="15"
VerticalAlignment="Center"
Foreground="{DynamicResource TextColor}"/>
</Expander.Header>
<Expander.Content>
<ItemsPresenter Margin="0"/>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
</ItemsControl>