Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created December 5, 2013 05:28
Show Gist options
  • Save dtchepak/7800565 to your computer and use it in GitHub Desktop.
Save dtchepak/7800565 to your computer and use it in GitHub Desktop.
public class ObservableItems<T> : INotifyPropertyChanged
{
private IEnumerable<T> _items;
public ObservableItems(IObservable<IEnumerable<T>> source, IEnumerable<T> initialValue)
{
Items = initialValue;
source
.ObserveOnDispatcher()
.Subscribe(x => Items = x);
}
public IEnumerable<T> Items
{
get { return _items; }
private set { _items = value; OnPropertyChanged(); }
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment