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 3631958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:27:52+00:00 2026-05-19T00:27:52+00:00

I have the following page layout in my application: <Grid x:Name=ContentPanel Grid.Row=1> <ScrollViewer x:Name=ScrollViewer1

  • 0

I have the following page layout in my application:

<Grid x:Name="ContentPanel"
      Grid.Row="1">

  <ScrollViewer x:Name="ScrollViewer1" 
                MaxHeight="600"
                VerticalAlignment="Top"
                HorizontalAlignment="Stretch">

    <StackPanel x:Name="StackPanel1" >
      <TextBlock x:Name="TextBlock1" />

      <toolkit:ListPicker  x:Name="ListPicker1" />

      <TextBlock x:Name="TextBlock2" />

      <TextBox x:Name="TextBlock3" />

      <TextBlock x:Name="TextBlock4" />

      <StackPanel x:Name="StackPanel2" >

        <TextBlock x:Name="TextBlock5" />

        <Image x:Name="Image1"/>

      </StackPanel>

      <ListBox x:Name="ListBox1">
        <!--Customize the ListBox template to remove the built-in ScrollViewer-->
        <ListBox.Template>
          <ControlTemplate>
            <ItemsPresenter />
          </ControlTemplate>
        </ListBox.Template>

        <ListBox.ItemTemplate>
          <DataTemplate>

            <!-- .... -->

          </DataTemplate>
        </ListBox.ItemTemplate>

        <ListBox.ItemContainerStyle>
          <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment"
                    Value="Stretch" />
          </Style>
        </ListBox.ItemContainerStyle>
      </ListBox>

    </StackPanel>

  </ScrollViewer>

</Grid>

I added an external ScrollViewer instead of the using the ListBox‘s because without it the stuff above the ListBox was taking too much room and not leaving enough space to view the ListBox contents.

Now, the problem is if I add an item to the end of the ListBox the ScrollIntoView method does not work. So I need to use the ScrollViewer‘s ScrollToVerticalOffset method.

I’m adding the new item to an ObservableCollection that is bound to the ListBox when the user clicks a button on the application bar. How can I calculate the value to be passed to ScrollViewer.ScrollToVerticalOffset?

Thanks for your help!

  • 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-19T00:27:52+00:00Added an answer on May 19, 2026 at 12:27 am

    You can find the container that the ListBox has generated to host your element. Once you have this container, you can find its position relative to the scrollviewer:

      var newItem = // the item you just added to your listbox
    
      // find the ListBox container
      listBox.UpdateLayout()
      var element = listBox.ItemContainerGenerator.ContainerFromItem(newItem) as FrameworkElement;
    
      // find its position in the scroll viewer
      var transform = element.TransformToVisual(ScrollViewer);
      var elementLocation = transform.Transform(new Point(0, 0));
      double newVerticalOffset = elementLocation.Y + ScrollViewer.VerticalOffset;
    
      // scroll into view
      ScrollViewer.ScrollToVerticalOffset(newVerticalOffset);
    

    Hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a route like following, ideally I would like it to match: domain.com/layout/1-slug-is-the-name-of-the-page
I have the following in my application layout page <body> <div class=container showgrid> <%=
I have the following layout in my page (simplified) <h:form> <h:commandButton action=#{bean.save} value=Save/> <rich:tabPanel
I am working on an asp.net MVC4 application. In my layout page, I have
I have the following page with a black canvas inside of it: There, the
I have the following page structure: <span>content01</span> <span>content02</span> <span>content03</span> <br/> <span>content04</span> <span>content05</span> <span>content06</span> <br/>
I have the following HTML page and the background color for the content is
I have the following Web page: link to page . If you go to
I have the following ASP page: <asp:Content ID=Content2 ContentPlaceHolderID=ShellContent runat=server> <form runat=server id=AddNewNoteForm method=post>
I have the following jQueryMobile page anatomy at index.html: <div data-role=page> <div data-role=header>...</div> <div

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.