Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:33:35+00:00 2026-05-11T23:33:35+00:00

In WPF, I know I can use ListView.ScrollIntoView to scroll a particular item into

  • 0

In WPF, I know I can use ListView.ScrollIntoView to scroll a particular item into view, but it will always do the least amount of scrolling so that the item is shown.

How can I make it scroll so that the item I want to show is scrolled to the top of the ListView?

I’ve thought about calling ScrollIntoView twice, once for the item I want at the top, and once for the last shown item, but I don’t know how to find out what the last shown item.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:33:35+00:00Added an answer on May 11, 2026 at 11:33 pm

    We can do this by obtaining the ScrollViewer that is present in the ListView’s ControlTemplate. If you have access to a ScrollViewer then there are a lot of different scrolling methods exposed.

    First, we can create a ListView that we want to add this effect to:

    <ListView ItemsSource="{Binding Percents}"
          SelectionChanged="OnSelectionChanged"
          x:Name="uiListView"/>
    

    public List<int> Percents { get; set; }
    
    public Window1()
    {
        InitializeComponent();
    
        Percents = new List<int>();
        for (int i = 1; i <= 100; i++)
        {
            Percents.Add(i);
        }
        this.DataContext = this;
    }
    

    We will also need something that we can use to obtain the ScrollViewer from the ListView. I’ve used something similar to this before to work with custom scrolling, and we can use it here as well.

    public static DependencyObject GetScrollViewer(DependencyObject o)
    {
        if (o is ScrollViewer)
        { return o; }
    
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(o); i++)
        {
            var child = VisualTreeHelper.GetChild(o, i);
    
            var result = GetScrollViewer(child);
            if (result == null)
            {
                continue;
            }
            else
            {
                return result;
            }
        }
    
        return null;
    }
    

    Now, we just need to handle the SelectionChanged event. Because we are trying to scroll an item to the top of the list, the best option is to scroll to the bottom, and then re-scroll up to our selected item. As you said, ScrollIntoView will scroll just until the item is visible, and so once the selected item reaches the top as it scrolls back up, it will cease leaving us with our selected item at the very top of the list.

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ScrollViewer scrollViewer = GetScrollViewer(uiListView) as ScrollViewer;
        scrollViewer.ScrollToBottom();
    
        uiListView.ScrollIntoView(e.AddedItems[0]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know where I can get a control like the Multi-column Tree-View in WPF?
I know that WPF 3.5 SP1 supports a StringFormat in a binding, but can
I know how to create a custom user control in WPF but how can
Anyone know how to style the header hover color of a WPF ListView? Thanks!
I would like to know if I can use FNT font file in c#
Does someone know a library that I can use to read MP3 tags in
I see several people saying that WPF can use Custom Type Descriptors for Change
So in WPF there is a CommandParameter attribute that you can use in your
The WPF Grid has an IsMouseOver property that you can use in the Grid's
I know in ASP.NET I can get an item from a DropDownList by using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.