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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:13:32+00:00 2026-06-01T13:13:32+00:00

I am using ObservableCollection as an ItemSource for my listBox component: But the behavior

  • 0

I am using ObservableCollection as an ItemSource for my listBox component:

But the behavior of the control is not proper as for me. The matter I have scroll down to ths first occurence in my collection, but not last.

The sample list is: 1,1,2,3,4,5,6,7,8,9,11,22,33,1

When you enetr last 1 you component scroll up to first 1 :). This not what I am wating for.

Please advise. Here a code of component:

public class MyListBox : ListBox
{
    protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        base.OnItemsChanged(e);
        if (Items.Count > 0)
        {
            var item = Items[Items.Count - 1];
            UpdateLayout();
            ScrollIntoView(item);
            UpdateLayout();
        }
    }

}
  • 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-06-01T13:13:33+00:00Added an answer on June 1, 2026 at 1:13 pm

    Sorry but it needs to be a class as a List or OC is going to really do a value comparison. So you need to make identical values unique. I test this out and it works.

         <StackPanel Orientation="Vertical" >
            <ListBox x:Name="lbStringList" ItemsSource="{Binding Path=UniqueStringList}" DisplayMemberPath="Str" Height="60" VerticalAlignment="Top"/>
            <Button Click="Button_Click" Content="56" />
         </StackPanel>
    
    
        private List<UniqueString> uniqueStringList = new List<UniqueString>() 
                {                   
                    new UniqueString("zero",0),
                    new UniqueString("one",1),
                    new UniqueString("two",2),
                    new UniqueString("three",3),
                    new UniqueString("four",4),
                    new UniqueString("five",5),
                    new UniqueString("six",6),
                    new UniqueString("seven",7),
                    new UniqueString("zero",8)
                }; 
    
        public MainWindow()
        {
            InitializeComponent();
    
        }
        public List<string> StringList { get { return new List<string>() { "one", "two", "three", "four", "five", "one" }; } }
        public List<UniqueString> UniqueStringList 
        { 
            get 
            {
                return uniqueStringList;
            } 
        }
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(sender.GetHashCode());
            lbStringList.ScrollIntoView(lbStringList.Items[8]);
    
        }
        public class UniqueString
        {
            private Int32 id;
            public string Str { get; private set; }
            public override bool Equals(object obj)
            {
                UniqueString item = (UniqueString)obj;
                return item.id == id;
            }
            public override int GetHashCode()
            {
                return id;
            }
    
            public UniqueString(string str, Int32 _id) { Str = str; id = _id; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox in WPF that's bound to a ObservableCollection using the ItemSource
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I've got an ObservableCollection assigned to ItemsSource of a listbox. Listbox is using a
I have a problem updating the layout of my listbox using MVVM with Prism
I have a ListBox which is bound to ObservableCollection of LogMessages. public ObservableCollection<LogMessage> LogMessages
I have built a view model and the listbox binds to the ObervableCollection, but
Is there a way to invalidate a listbox which using as itemssource an ObservableCollection
I have a listbox which is bound to a CollectionViewSource (backed by an ObservableCollection).
I'm using an observable collection to hold all files dragged into a ListBox control

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.