0

Need to build image explorer with expanders, but I have some problem with scrolling. I have ItemsControl with ListBox inside, scroll do not work when mouse on ListBox. Here is xaml:

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Grid.Row="1" Background="{DynamicResource LightGrayBackgroundBrush}" >
    <ItemsControl x:Name="itmsControl"  DataContext="{Binding ElementName=_self}" ItemsSource="{Binding ImagesSource}"  Margin="15" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid x:Name="grdIn">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" MinHeight="25"/>
                        <RowDefinition x:Name="grd1"/>
                    </Grid.RowDefinitions>

                    <Expander Grid.Row="1" IsExpanded="True" BorderThickness="0" Background="White">
                        <Expander.Header>
                            <Border Background="White" BorderBrush="White" Height="40">
                                <TextBlock Text="{Binding Date}" Background="White" FontSize="14" Foreground="Gray" FontWeight="Bold" VerticalAlignment="Center" Margin="10,0,0,0"/>
                            </Border>
                        </Expander.Header>

                        <ListBox ItemsSource="{Binding ImageList}" ItemContainerStyle="{DynamicResource ImageListBoxItemStyle}"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionMode="Extended" Background="Transparent" SelectionChanged="ListBox_SelectionChanged" PreviewKeyDown="OnKeyDownHandler" MouseDown="ListBox_MouseDown" ScrollViewer.CanContentScroll="False">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Image Stretch="UniformToFill" Width="{Binding Width}" Height="{Binding Height}" Source="{Binding Source}" Margin="3" MouseDown="Image_MouseDown"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <ListBox.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel IsItemsHost="True" Orientation="Horizontal" />
                                </ItemsPanelTemplate>
                            </ListBox.ItemsPanel>
                        </ListBox>
                    </Expander>
                </Grid>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>
ASh
  • 34,632
  • 9
  • 60
  • 82
  • Possible duplicate of [Listview inside of scrollviewer prevents scrollviewer scroll](https://stackoverflow.com/questions/8932720/listview-inside-of-scrollviewer-prevents-scrollviewer-scroll) – Martin Schneider May 14 '19 at 11:25

3 Answers3

0

Do you want to scroll ScrollViewer only? Then why do you use ListBox inside ItemsControl? I watch that you block scrolling of ListBox

ScrollViewer.CanContentScroll="False"

But ListBox has ScrollViewer inside his template. And I think that this ScrollViewer handle "mouse whell" event and it does not reach the root ScrollViewer. I think that you can fix your problem if you just replace ListBox to ItemsControl.

Egor Novikov
  • 416
  • 8
  • 24
0

change xaml with this:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <ScrollViewer>
            <WrapPanel IsItemsHost="True" Orientation="Horizontal" />
        </ScrollViewer>
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
0

When you select Listbox image, focus is lost for scroll viewer. So, you can set focus to scroll viewer on MouseWheel/PreviewMouseWheel event or you can scroll manually like below.

myScroll.ScrollToVerticalOffset(myScroll.VerticalOffset + 10);
Maulik Parmar
  • 857
  • 10
  • 15
  • I added PreviewMouseWheel to ListBox: private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { mainScroll.ScrollToVerticalOffset(mainScroll.VerticalOffset - e.Delta); } It is works, thanks Maulik :) – Murtaz Pachulia Nov 17 '16 at 07:15