IObservablewhich is then built upon by XAML bindings (which can also be instantiated in code).
GetObservablemethod. This returns an
IObservable<T>which can be used to listen for changes to the property:
[PropertyName]Propertywhich is passed to
GetObservablein order to subscribe to the property's changes.
IObservable(part of Reactive Extensions, or rx for short) is out of scope for this guide, but here's an example which uses the returned observable to print a message with the changing property values to the console:
Bindmethod returns an
IDisposablewhich can be used to terminate the binding. If you never call this, then then binding will automatically terminate when the observable finishes via
IDisposableis returned. If you need to manually terminate the binding then you should use the
IDisposableto terminate the binding:
GetObservablemethod returns an observable that tracks changes to a property on a single instance. However, if you're writing a control you may want to implement an
OnPropertyChangedmethod which isn't tied to an instance of an object.
In WPF this is done by passing a static
DependencyPropertyregistration method, but this only allows the control author to register a property changed callback.
AddClassHandlerextension method which can automatically route the event to a method on your control.
Fooproperty you'd do it like this:
INotifyPropertyChangedis also available.