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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:34+00:00 2026-05-26T07:27:34+00:00

Edited to address F Ruffell’s answer I have the following xaml <StackPanel> <ListBox x:Name=_list1/>

  • 0

Edited to address F Ruffell’s answer

I have the following xaml

<StackPanel>
    <ListBox x:Name="_list1"/>
    <ListBox x:Name="_list2"/>
</StackPanel>

and this code-behind:

var ints = new[] { 1, 2, 3 };
_list1.ItemsSource = ints;
_list2.ItemsSource = ints;

_list1.Items.Filter = i => ((int)i) < 2;

For some reason after setting filter only for the first ListBox both lists are filtered. I expect the lists to have completely different CollectionViews and indeed _list1.Items != _list2.Items. Meanwhile setting filter to one of them also somehow sets that very filter to the other.
The question is why and how are CollectionViews synchronized?

  • 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-26T07:27:34+00:00Added an answer on May 26, 2026 at 7:27 am

    The question is why and how are CollectionViews synchronized?

    They are synchronized because even though both ListBoxes have different Items, they share the same CollectionView, which is the default view for the source collection.

    The Items property of ItemsControl is of type ItemCollection and the CollectionView property of ItemCollection is internal so we can’t access it directly to verify that this is true. However, we can just enter these three values in the debugger to verify this, they all come out as true

    _list1.Items.CollectionView == _list2.Items.CollectionView // true
    _list1.Items.CollectionView == CollectionViewSource.GetDefaultView(ints) // true
    _list2.Items.CollectionView == CollectionViewSource.GetDefaultView(ints) // true
    

    Alternatively, we can use reflection to do the comparison in code

    PropertyInfo collectionViewProperty =
        typeof(ItemCollection).GetProperty("CollectionView", BindingFlags.NonPublic | BindingFlags.Instance);
    ListCollectionView list1CollectionView = collectionViewProperty.GetValue(_list1.Items, null) as ListCollectionView;
    ListCollectionView list2CollectionView = collectionViewProperty.GetValue(_list2.Items, null) as ListCollectionView;
    ListCollectionView defaultCollectionView = CollectionViewSource.GetDefaultView(ints) as ListCollectionView;
    
    Debug.WriteLine(list1CollectionView == list2CollectionView);
    Debug.WriteLine(list1CollectionView == defaultCollectionView);
    Debug.WriteLine(list2CollectionView == defaultCollectionView);
    

    The way to work around this has already been posted by F Ruffell, create a new ListCollectionView as ItemsSource for each ListBox.

    _list1.ItemsSource = new ListCollectionView(ints);
    _list2.ItemsSource = new ListCollectionView(ints);
    

    Also note that after this, the 3 comparisons above comes out as false

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

Sidebar

Related Questions

--edited for clarity (hopefully) I have an XML file that looks something like this:
I have an xml like this <address> <street>abc</street> <number>123</number> </address> <address> <street>abc1</street> <number>345</number> </address>
Hi there I have edited some code I have found on-line and everything works
I am trying to understand virtual memory paging. I have the following code snippet
I implement some thing like this - person grid - name address action a
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Edited: SOLUTION FOUND. This is strange and not the best solution, but I just
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
Edited to Add * I haven't found a solution for this one yet, can
edited, this is it function handleDate( timestamp ) { var n=new Date(), t, ago

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.