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

  • SEARCH
  • Home
  • 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 6534647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:16:32+00:00 2026-05-25T10:16:32+00:00

I do have a listbox which must have CanContentScroll==false because i need to be

  • 0

I do have a listbox which must have CanContentScroll==false because i need to be able to scroll it smoothly. This enables physical scrolling.

I also want to scroll the listbox by page, but if i call the PageDown method on the listbox internal ScrollViewer the first row gets cutted because the listbox height is not a multiple of the row height.

I want the first row to be always completely visible, like when using logical scrolling.

Can someone give me a hint on how to do that?

  • 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-25T10:16:33+00:00Added an answer on May 25, 2026 at 10:16 am

    You’ll get the same effect for a non virtualizing ItemsControl (ScrollViewer.CanContentScroll="False") as for a virtualizing one if you scroll down and then select the upper visible container with the mouse. This can also be done in code.

    When CanContentScroll is set to false, virtualizing is turned off so all containers will be generated at all times. To get the top visible container we can iterate the containers from the top until we reach the VerticalOffset of the ScrollViewer. Once we got it we can simply call BringIntoView on it and it will align nicely at the top just like it would if virtualization was being used.

    Example

    <ListBox ItemsSource="{Binding MyCollection}"
             ScrollViewer.CanContentScroll="False"
             ScrollViewer.ScrollChanged="listBox_ScrollChanged" >
    

    Call BringIntoView on the top visible container in the event handler

    private void listBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
    {
        ItemsControl itemsControl = sender as ItemsControl;
        ScrollViewer scrollViewer = e.OriginalSource as ScrollViewer;
        FrameworkElement lastElement = null;
        foreach (object obj in itemsControl.Items)
        {
            FrameworkElement element = itemsControl.ItemContainerGenerator.ContainerFromItem(obj) as FrameworkElement;
            double offset = element.TransformToAncestor(scrollViewer).Transform(new Point(0, 0)).Y + scrollViewer.VerticalOffset;
            if (offset > e.VerticalOffset)
            {
                if (lastElement != null)
                    lastElement.BringIntoView();
                break;
            }
            lastElement = element;
        }
    }
    

    To only achieve this effect when you want to call PageDown, in a Button click for example, you can create an extension method for ListBox called LogicalPageDown.

    listBox.LogicalPageDown();
    

    ListBoxExtensions

    public static class ListBoxExtensions
    {
        public static void LogicalPageDown(this ListBox listBox)
        {
            ScrollViewer scrollViewer = VisualTreeHelpers.GetVisualChild<ScrollViewer>(listBox);
            ScrollChangedEventHandler scrollChangedHandler = null;
            scrollChangedHandler = (object sender2, ScrollChangedEventArgs e2) =>
            {
                scrollViewer.ScrollChanged -= scrollChangedHandler;
                FrameworkElement lastElement = null;
                foreach (object obj in listBox.Items)
                {
                    FrameworkElement element = listBox.ItemContainerGenerator.ContainerFromItem(obj) as FrameworkElement;
                    double offset = element.TransformToAncestor(scrollViewer).Transform(new Point(0, 0)).Y + scrollViewer.VerticalOffset;
                    if (offset > scrollViewer.VerticalOffset)
                    {
                        if (lastElement != null)
                            lastElement.BringIntoView();
                        break;
                    }
                    lastElement = element;
                }
            };
            scrollViewer.ScrollChanged += scrollChangedHandler;
            scrollViewer.PageDown();
        }
    }
    

    I noticed in your question that you already got the ScrollViewer but I’m adding an implementation to GetVisualChild if anyone else comes across this question

    public static T GetVisualChild<T>(DependencyObject parent) where T : Visual
    {
        T child = default(T);
    
        int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
        for (int i = 0; i < numVisuals; i++)
        {
            Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
            child = v as T;
            if (child == null)
            {
                child = GetVisualChild<T>(v);
            }
            if (child != null)
            {
                break;
            }
        }
        return child;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[Original] I have a ListBox which has its ItemsSource (this is done in the
I have a Listbox DataTemplate which looks like this <DataTemplate> <StackPanel Margin=0,24,0,24> <StackPanel toolkit:TiltEffect.IsTiltEnabled=true>
I have listbox which binds data to DataTable and now I need to access
I have this ListBox which is bound to an ObservableCollection. Each object in the
I have a ListBox which contains objects describing a person. This objects are only
Within my project I have a Listbox which uses a datatemplate. Within this data
I have a listbox which acts as a list of items. If you click
I have a ListBox which uses a DataTemplate to render databound items. The XAML
I have a Listbox which work with specific extension files. If i choose another
So, I have a ListBox which is bound to a list of business objects,

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.