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
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.
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.
Due to a limitation with the Expression
class in Silverlight and Windows Phone, Rxx does not offer the primary overload of
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
on these platforms. FromPropertyChangedPattern
conversions for WPF.
Download the labs application for your target platform and then run the Property Changed Events
lab. This lab contains working examples of
. The source code for the lab is displayed in the application, for your convenience.
For more information, see
Rxx Hands-on Labs