Viewmodel property to observable stream

When implementing a user interface in WPF/MVVM applications we frequently encounter situations where we want to be able to react on all changes made to a particular property.

One way to handle this is to create an observable sequence of values with Reactive Extensions (Rx). This is especially valuable if we have other event streams that interact with the property changed events.

There are several libraries around that can help with this like e.g. ReactiveUI or ReactiveProperty.

But if we want a lightweight, generic, reusable, and typesafe solution, we can consider just using the following extension method, which can be called on any instance that implements INotifyPropertyChanged. It retrieves the property name from the expression that is passed in, converts all PropertyChanged events into an observable sequence, and then finds the value of the right property using reflection.

Continue reading →

Series: Reactive Extensions in theory and practice

Reactive Extensions is a library for composing event based programs using observable sequences and LINQ-style query operators.

I wrote a series of blog posts on Reactive Extension covering some theory and including some practical examples in C#:

Series: Reactive Extensions in theory and practice

  1. Short introduction to Reactive Extensions
  2. Visualizing sequences
  3. Drawing lines with Rx
  4. Twitter with Rx