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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:25+00:00 2026-05-15T18:48:25+00:00

Imagine the following: class Repository { private ObservableCollection<ModelClass> _allEntries; public ObservableCollection<ModelClass> AllEntries { get

  • 0

Imagine the following:

class Repository
{
    private ObservableCollection<ModelClass> _allEntries;
    public ObservableCollection<ModelClass> AllEntries
    {
        get { return _allEntries; }
        set { _allEntries = value; }
    }
    public void RefreshDataFromDB()
    {
        _all = new ObservableCollection(GetMyData()); // whatever method there is
    }
}

Now there are a couple of controls that bind to this collection, e.g.:

<ListView ItemsSource="{Binding Repository.AllEntries, ElementName=Whatever}"/>

The problem now is that if I call the RefreshDataFromDB the bindings get lost (at least it seems so) as the _all is now pointing to new memory part and the bindings still use the old reference. INotifyPropertyChanged does not help me in this case (e.g. putting it in RefreshDataFromDB does not help a lot).

The question would be – how would you handle a case where you replce a collection and want to update its consumers’ bindings?

  • 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-15T18:48:26+00:00Added an answer on May 15, 2026 at 6:48 pm

    Yes; you’re not modifying the collection, the UI is bound to the collection, and then you replace it with a new one.

    You could do this:

    _all.Clear();
    _all.AddRange(GetMyData());
    

    Hope that helps!


    Alternatively, make AllEntries (or All.. your nomenclature seems to change a few times on the post ;)) a DependencyProperty:

    public static DependencyProperty AllEntriesProperty = DependencyProperty.Register("AllEntries", typeof(ObservableCollection), typeof(MyClass));
    

    You’d need to make the get/set property too, see here for an example:

    http://msdn.microsoft.com/en-us/library/ms752914.aspx

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

Sidebar

Related Questions

Imagine the following classes: class A { public string Test {get; set;} } class
Imagine the following situation: class IAlarm : public boost::enable_shared_from_this<IAlarm> { boost::shared_ptr<IAlarm> getThisPointerForIAlarm() { return
Imagine the following code: class foreach_convert { public static void method2() { List<IComparable> x
Give the following class: public Person { public string Name {get; set;} public string
Just imagine you have the following class [DataContract] public class NamedList { [DataMember] public
Imagine the following VB.NET class: Public Class P Public Function GetDumbList() As List(Of DumbPeople)
Imagine the following two classes of a chess game: TChessBoard = class private FBoard
Consider the following sample code: class MyClass { public long x; public void DoWork()
Imagine the following scenario: template<class T> void myFunction(T *) { //do nothing } void
Imagine the following code, written in C#: public class Provider<T> { T GetValue(); //

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.