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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:43:26+00:00 2026-05-22T20:43:26+00:00

How to get next sibling of the element in visual tree? This elment is

  • 0

How to get next sibling of the element in visual tree? This elment is dataitem of the databound ItemsSource. My goal is get acces to sibling in code (assume that i have access to the element itself) and then use BringIntoView.

Thanks.

  • 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-22T20:43:27+00:00Added an answer on May 22, 2026 at 8:43 pm

    For example, if your ItemsControl is a ListBox, the elements will be ListBoxItem objects. If you have one ListBoxItem and you want the next ListBoxItem in the list, you can use the ItemContainerGenerator API to find it like this:

    public static DependencyObject GetNextSibling(ItemsControl itemsControl, DependencyObject sibling)
    {
        var n = itemsControl.Items.Count;
        var foundSibling = false;
        for (int i = 0; i < n; i++)
        {
            var child = itemsControl.ItemContainerGenerator.ContainerFromIndex(i);
            if (foundSibling)
                return child;
            if (child == sibling)
                foundSibling = true;
        }
        return null;
    }
    

    Here’s some sample XAML:

    <Grid>
        <ListBox Name="listBox">
            <ListBoxItem  Name="item1">Item1</ListBoxItem>
            <ListBoxItem Name="item2">Item2</ListBoxItem>
        </ListBox>
    </Grid>
    

    and the code-behind:

    void Window_Loaded(object sender, RoutedEventArgs e)
    {
        var itemsControl = listBox;
        var sibling = item1;
        var nextSibling = GetNextSibling(itemsControl, sibling) as ListBoxItem;
        MessageBox.Show(string.Format("Sibling is {0}", nextSibling.Content));
    }
    

    which results in:

    Sibling MessageBox

    This also works if the ItemsControl is data-bound. If you only have the data item (not the corresponding user interface element), you can use the ItemContainerGenerator.ContainerFromItem API to get the initial sibling.

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

Sidebar

Related Questions

I want to get the .next() and .prev() sibling of an HTML element without
I need to get the next sibling of an element but it should not
When trying to get next activities it shows this error: This page contains the
I want to increment $x in this function to get next record in table.
I want to get the next select element (because there will be multiple with
In order to get the next element in the list one just needs to
How do you get to the next node below this For example <ul id=secondary-nav>
I have next interface public interface IMyInterface { string this[string key] { get; set;
What I need to do is get the next element which isn't of the
I have an element grabbed from document.getElementById('the_id') . How can I get its next

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.