WPF listview vertical scrollbar

Try adding a scrollViewer in DataTemplate like below,

<DataTemplate>
 <ScrollViewer>
   <TextBlock TextWrapping="Wrap" Text="{Binding}"/>
 </ScrollViewer>
</DataTemplate>

Yous just need to limit the height of your ListView with MaxHeight propertie Exemple:

<ListView  ItemsSource="{Binding Path=InkersList}"
           MaxHeight="400">
   <ListView.Resources>
       <DataTemplate DataType="{x:Type VM:InkerVM}">
               <Views:InkerView />
       </DataTemplate>
   </ListView.Resources>
</ListView>  

                            

Set ScrollViewer.CanContentScroll="False" on your ListView.

<ListView ItemsSource="{Binding Path=ReportEntries}"  
          VerticalContentAlignment="Top"  
          ScrollViewer.VerticalScrollBarVisibility="Visible"
          ScrollViewer.CanContentScroll="False">
    <!-- etc. -->
</ListView>

The ListView is trying to virtualize, by default. Virtualizing means, among other things, using logical scroll. Logical scrolling means the ScrollViewer scrolls item by item, jumping from one item to another instead of smoothly scrolling through the whole extent of each item.

By setting CanContentScroll to false, you're telling the ScrollViewer to stop using logical scrolling, which also deactivates virtualization.

If you're gonna show LOTS of items in that ListView, maybe virtualization is a big deal and this will introduce a performance issue.

If you're just gonna show a handful of items, then this should be completely fine.

EDIT - If performance is indeed an issue and you need to keep virtualization activated, consider setting a fixed height for all rows and adding its own ScrollViewer around the TextBlock with the big text.

Tags:

Wpf