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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:55:24+00:00 2026-06-13T12:55:24+00:00

I cant figureout why my ICollectionView is not refreshed. Can anyone explain what I’m

  • 0

I cant figureout why my ICollectionView is not refreshed. Can anyone explain what I’m doing wrong?

I’ve made a viewmodel like this:

class ViewModel : INotifyPropertyChanged
{
    private ObservableCollection<Entity> m_entities = new ObservableCollection<Entity>();
    public ICollectionView EntitiesView { get; private set; }
    public ICollectionView HighCountView { get; private set; }

    public ViewModel()
    {
        m_entities.Add(new Entity() { Id = 1, Name = "Erik", Description = "The first" });
        m_entities.Add(new Entity() { Id = 2, Name = "Olle", Description = "The second" });
        m_entities.Add(new Entity() { Id = 3, Name = "Kim", Description = "The last" });


        EntitiesView = CollectionViewSource.GetDefaultView(m_entities);
        EntitiesView.CurrentChanged += new EventHandler(EntitiesView_CurrentChanged);

        HighCountView = new CollectionView(m_entities);
        using (HighCountView.DeferRefresh())
        {
            HighCountView.Filter = e => ((Entity)e).Count > 3;
        }

    }

    private void EntitiesView_CurrentChanged(object sender, EventArgs e)
    {
        Entity current = EntitiesView.CurrentItem as Entity;
        if(current!=null)
        {
            current.Count++;
            HighCountView.Refresh();            // Do I need this line?
            OnPropertyChanged("HighCountView"); // or this?
        }
    }

…and in my window I use it as the datacontext, like this:

public partial class MainWindow : Window
{
    private ViewModel vm = new ViewModel();
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = vm;
    }
}

…and I’m doing my bindings in the XAML-code like this:

    <ListBox Grid.Column="0" x:Name="listView1" DisplayMemberPath="Name" ItemsSource="{Binding EntitiesView}" IsSynchronizedWithCurrentItem="True" />
    <ListView Grid.Column="1" x:Name="listView2" DisplayMemberPath="Name" ItemsSource="{Binding HighCountView}" IsSynchronizedWithCurrentItem="True" />

The problem is that all three Entities is always shown in listView2 despite that I set the Filter-property. Why?

EDIT

To made the sample complete, here is the Entity-class.

class Entity : INotifyPropertyChanged
{
    private int m_id;
    public int Id
    {
        bla bla.....
    }

    private string m_name;
    public string Name
    {
        bla bla.....
    }

    private string m_description;
    public string Description
    {
        bla bla.....
    }


    private int m_count;
    public int Count
    {
        get { return m_count; }
        set
        {
            if (value != m_count)
            {
                m_count = value;
                OnPropertyChanged("Count");
            }
        }
    }

    public void Update()
    {
        Description = "Updated: " + (++Count).ToString() + " times.";
    }
  • 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-13T12:55:25+00:00Added an answer on June 13, 2026 at 12:55 pm

    At last I found what was wrong.

    If I change the line:

        HighCountView = new CollectionView(m_entities);
    

    to this

        HighCountView = new ListCollectionView(m_entities);
    

    then it works a expected.

    I can also remove this line

            OnPropertyChanged("HighCountView"); // or this?
    

    I hope this can help somebody!

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

Sidebar

Related Questions

This seems in my head like it should work but I cant figure out
Total newbie question, but I cant figure out what im doing wrong. I want
I cant really figure out whats wrong with this. I used to write the
im cant figure out what is wrong with my code if someone can help
I cant figure out why the this alert() part below is not working when
I cant figure out why this is not working. Basicly the following code-snippet workes
I cant figure out what I am doing wrong here that throws me a
I want to do something but cant figure out how to do this (i
I am getting segmentation fault in this code but i cant figure out why.
I cant figure out whats wrong. Its working when i tried to refresh only

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.