Search code examples
c#wpflistviewscrollview

Scrollbar that does not work when the mouse is placed on a Listview


I have a Listview, inside a ScrollViewer.

I have the problem that the scrollbar managed by the mouse does not work when the pointer is on the Listview, if I exit the list the scrollbar works correctly.

Preview

 <ScrollViewer   Grid.Row="2"  IsTabStop="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" CanContentScroll="True">
        <Grid  Grid.Row="2" MinWidth="500" MaxWidth="1000" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0" ItemsSource="{Binding Notifications}" x:Name="ListeNouvellesNotifs" BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <ListView.ItemTemplate>

Do I have to change the object to show the list or can I use the Listview?

I tried to disable the ScrollViewer from the Listview, it doesn't work.

I believe that when the mouse is over it cannot recall the scroll of the container


Solution

  • You add a < listview.template >

     <ScrollViewer Grid.Row="2"  IsTabStop="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <Grid Grid.Row="2" MinWidth="500" MaxWidth="1000">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto"/>
                        <RowDefinition Height="auto"/>
                    </Grid.RowDefinitions>
                    <ListView Grid.Row="0" ItemsSource="{Binding Notifications}" x:Name="ListeNouvellesNotifs" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Hidden">
                        <ListView.Template>
                            <ControlTemplate>
                                <ItemsPresenter></ItemsPresenter>
                            </ControlTemplate>
                        </ListView.Template>
                        <ListView.ItemTemplate>