Take the 2-minute tour ×

I'm fan of Reactive Extension and especially ReactiveUI I have DP in other solution's project than mine. I'd like to convert this into observable Class containing this DP is internal and derived from DependencyObject thus I cannot use Class.ObservableFromDP because class must be derived from FrameworkElement

I have this solution

public static IObservable<T> ToObservable<T>(this DependencyObject dependencyObject, DependencyProperty property)
        return Observable.Create<T>(o =>
                                            var des = DependencyPropertyDescriptor.FromProperty(property,
                                            var eh =
                                                new EventHandler(
                                                    (s, e) => o.OnNext((T) des.GetValue(dependencyObject)));
                                            des.AddValueChanged(dependencyObject, eh);
                                            return () => des.RemoveValueChanged(dependencyObject, eh);

But target class is internal, I cannot access property DependencyProperty in this class

How can I get Observable from this property

Is there any method as

obj.ObservableFromDP(x=>x.ActiveEditor) working on obj not derived from FrameworkElement?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This is actually fixed in >= ReactiveUI 4.0. Now all you do is:

// WhenAny now works on any object, will detect DependencyObject automatically
obj.WhenAny(x => x.ActiveEditor, x => x.Value)
   .Subscribe(/* ... */)
share|improve this answer
Paul, may I ask you? Why you removed ObservableFromDP from ReactiveUI 4 instead of making it deprecated? –  takayoshi Dec 14 '12 at 9:18
It's not removed, just generalized. WhenAny now works with DependencyObjects and DependencyProperties, not just ViewModel objects. The same functionality is there, the name is just different –  Paul Betts Dec 14 '12 at 9:47
add comment

Your Answer


