This project has moved and is read-only. For the latest updates, please go here.

FromPropertyChangedPattern

.NET 4.0 Silverlight 4 Silverlight 5 Phone 7.0 Phone 7.1
S.png P.png P.png P.png P.png

Overview

Converting property changed events into an observable sequence of property values is a common requirement among developers using Rx. There have been numerous attempts at generalizing this requirement into an operator, but they do not take full advantage of compiler support to simplify the operator's signature nor do they use the standard FCL methods that apply to acquiring property changed events from any object using standard techniques.

Rxx provides Observable2.FromPropertyChangedPattern, which is an overloaded static factory method that acquires a change event for a property of a compatible object and converts it into an observable sequence of values that is updated whenever the property changes.

The following list specifies the types and events that FromPropertyChangedPattern supports to convert a single property into an observable sequence. They are mutually exclusive, so any of the following may be implemented. At least one must be implemented; otherwise, an exception is thrown.
FromPropertyChangedPattern uses an Expression parameter to specify the object and property to be converted, based on an idea from a discussion in the Rx forum. There is also an overload that allows you to specify an object explicitly, although it's generally not needed.

Platform Support

Due to a limitation with the Expression class in Silverlight and Windows Phone, Rxx does not offer the primary overload of FromPropertyChangedPattern on these platforms. To use FromPropertyChangedPattern, you must specify the object as an argument and then bind it to a variable in your lambda expression, even if you do not use the variable to return the property.

Due to lack of support for property descriptors in Silverlight and Windows Phone, Rxx does not support conversions from DependencyProperty on these platforms. FromPropertyChangedPattern only supports DependencyProperty conversions for WPF.

Lab

Download the labs application for your target platform and then run the Property Changed Events lab. This lab contains working examples of FromPropertyChangedPattern. The source code for the lab is displayed in the application, for your convenience.

For more information, see Rxx Hands-on Labs.

Last edited Mar 10, 2012 at 5:29 PM by davedev, version 4