3

I have a ScrollViewer with ListView inside. And I can't scroll ListView content by mouse wheel or touch. For example,

    <ScrollViewer x:Name="MyScroll" IsManipulationEnabled="False">
        <ListView x:Name="MyList" ItemsSource="{Binding Items}"/>
    </ScrollViewer>

The issue is the ListView has inside ScrollViewer in control template. You can't refuse from ListView ScrollViewer couse it contains GridViewHeaderRowPresenter class. It need to display headers of gridview columns if you use it with ListView.

To solve touch problem you need do:

  1. Use PanningMode property with Both value for outer SrcollViewer.

  2. Use PanningMode property with None value for ScrollViewer inside ListView ControlTemplate.

To solve mouse wheel problem see https://stackoverflow.com/a/7003338/7819575 using attached behaviors.

As a result we get next code:

    <ScrollViewer x:Name="MyScroll" PanningMode="Both">
        <ListView x:Name="MyList" ItemsSource="{Binding Items}">
            <ListView.Template>
                <ControlTemplate TargetType="{x:Type ListView}">
                    <Themes:ListBoxChrome x:Name="Bd" ...>
                        <ScrollViewer PanningMode="None" ...>
                            <ItemsPresenter .../>
                        </ScrollViewer>
                    </Themes:ListBoxChrome>
                    <ControlTemplate.Triggers>
                        ...
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </ListView.Template>
            <i:Interaction.Behaviors>
                <behaviors:IgnoreMouseWheelBehavior />
            </i:Interaction.Behaviors>
        </ListView>
    </ScrollViewer>

I hope this solution helps someone.

Anri
  • 41
  • 7

0 Answers0