This is a mirror of official site: http://jasper-net.blogspot.com/

Bubbling PropertyChanged Events in Silverlight

| Wednesday, October 20, 2010
I’ve been working with Silverlight (specifically for Windows Phone 7) recently and something I’ve found useful is the ability to “bubble” PropertyChanged event up. So for example;

   public class MainPageViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<Person> People
        {
            get
            {
                return  _repository.Items;
            }
        }

        // ... other members ommitted
    }

In this situation I have a repository of Person objects, and that repository implements INotifyPropertyChanged. But I don’t want to expose the repository as part of my View Model because that defeats the point of my encapsulation!
Now, if the ObservableCollection contents change, my View will get notified via the CollectionChanged event and will update itself. But if the repository destroys and replaces the whole collection, the View will never be notified.

My Solution

As a solution to this, I created a very simple class, as follows;

Read more: Simon Ince's Blog

Posted via email from .NET Info

0 comments: