Two WhenAny on different DP at one object #145

Closed
takayoshiSimizu opened this Issue Dec 23, 2012 · 6 comments

Comments

Projects
None yet
3 participants
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        RxApp.DeferredScheduler = DispatcherScheduler.Current;
        InitializeComponent();
        this.WhenAny(i => i.Width, i => i.Value).Subscribe(_ => SomeMethod("Width"));
        this.WhenAny(i => i.Height, i => i.Value).Subscribe(_ => SomeMethod("Height"));
    }

    void SomeMethod(string hello)
    {
        MessageBox.Show(hello);
    }

   }

When I resize it by height I've expected to see messagebox message "Height", but there is no such message

When I resize it by width I've expected to see messagebox message "Width", but there are two consecutive messagebox "Width" and "Height"

I can confirm this behaviour I have some code

this.CurvePlotter.WhenAny(x => x.Scale, x => x.Value).BindTo(ViewModel, x=>x.Scale);
this.CurvePlotter.WhenAny(x => x.Offset, x => x.Value).BindTo(ViewModel, x=>x.Offset);

Depending on the order in which I write these in the code different things happen.
In the current order ViewModel.Offset never get's updated if CurvePlotter.Offset
changes.

If I swap the code to be

this.CurvePlotter.WhenAny(x => x.Offset, x => x.Value).BindTo(ViewModel, x=>x.Offset);
this.CurvePlotter.WhenAny(x => x.Scale, x => x.Value).BindTo(ViewModel, x=>x.Scale);

then offset is updated. I've looked at the binding code for DependencyObjectObservableForProperty
and there is no obvious reason for this happening. Each WhenAny should be independant.

Owner

paulcbetts commented Jan 30, 2013

Can one of you create a PR that adds a failing test for this bug?

I've been trying to create a simplified test for this by extending your
tests but to no avail. Your code looks fine and I've tried to approach the
complexity if my runtime code but nothing breaks.

I start to wonder if there a bug in the event handling code for wpf. You
are about the only person who uses this feature of dependency props
external to m$
On Jan 30, 2013 7:13 PM, "Paul Betts" notifications@github.com wrote:

Can one of you create a PR that adds a failing test for this bug?


Reply to this email directly or view it on GitHubhttps://github.com/reactiveui/ReactiveUI/issues/145#issuecomment-12903735.

Owner

paulcbetts commented Jan 30, 2013

@bradphelan I've had that suspicion too - it only seems to happen with DependencyProperties.

And that would be a tragedy cause I've totally bought into the WhenAny
everywhere mindset. So have you seen suspicious behaviour with DP's and
WhenAny. If so under what conditions?

Is it possible that adding event handlers from the wrong thread onto DP's
causes bad things to happen because it seems that the DP's change event
dispatcher is corrupted somehow.

On Wed, Jan 30, 2013 at 8:17 PM, Paul Betts notifications@github.comwrote:

@bradphelan https://github.com/bradphelan I've had that suspicion too -
it only seems to happen with DependencyProperties.


Reply to this email directly or view it on GitHubhttps://github.com/reactiveui/ReactiveUI/issues/145#issuecomment-12906995.

@bradphelan bradphelan added a commit to bradphelan/ReactiveUI that referenced this issue Jan 31, 2013

@bradphelan bradphelan #145 An alternate way to handle DP WhenAny
Why: It's possible that the AddHandler method with DP's is buggy and
it is not used very much. Replace it with a more common idiom that is
used often and more robust

How: Inject a proxy DependencyObject with a single DependencyProperty
called value between the source object and the WhenAny operation. The
proxy object implements a standard DP callback which then calls onNext
on a standard Rx Subject which in turn is hooked into the WhenAny
architecture

Does This Fix The Problem: Not sure yet as I haven't tested it against
my failing code and I can't replicate the error in the tests even though
I've made the test more robust.
718e9c1
Owner

paulcbetts commented Feb 3, 2013

I believe that this issue should be solved in 4.3.2 - if not, please reopen

paulcbetts closed this Feb 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment