3

I recently added a OneWayToSource binding in our code to a read-only property in a view model. At the time I did not know about the change in .Net 4, that this will cause an exception when there is no getter:

<Popup IsOpen="{Binding IsPopupOpen, Mode=OneWayToSource}" />
...
public bool IsPopupOpen
{
    set
    {
        // do something with value
    }
}

The problem is, this code works on my computer without throwing an exception. The exact same executable does not work on other machines - the popup does not open, and the expected exception gets thrown. I cannot figure out how this is possible? The project targets .Net FW 4.

I made sure to clear out my bin folder and rebuild, but it is still working without exception on my machine, and not on others.

I know how to "fix" this - simply add a getter to the property. However I need to figure out how the program is functioning differently on different machines, as this could cause other serious issues...

EDIT:

This is driving me mad! I look at my popup using Snoop WPF utility, and there appears to be no binding to IsOpen at all (the binding is a new addition to the XAML). However, if I attach the debugger to the app and set a breakpoint inside the setter of the bound property, it hits my breakpoint!!

5
  • may be you mean write only property? Commented Feb 19, 2013 at 21:30
  • btw, didn't know about this change, thanks. Commented Feb 19, 2013 at 21:40
  • Thanks, I did mean write-only :) Fixed the title. Commented Feb 19, 2013 at 21:48
  • any progress? Also want to know the reasons of different behavior. Commented Feb 25, 2013 at 13:16
  • Thanks, this does appear to be reverted in 4.5, and we only had 4.0 on our target machines. Commented Feb 26, 2013 at 16:48

1 Answer 1

2

A bit of guessing.

There's plausible that after this change in net 4.0 they decided to make it more consistent in .net 4.5: if getter exists property is reread back to UI, otherwise nothing terrible happens and no exception is thrown.

If so and you have .net 4.5 installed you can get this behavior instead of the expected one.
We've met cases when updates to 4.5 propagated to 4.0 silently.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so much! I'm going to test this out - my coworker has 4.5 on his machine and he is pretty sure it was NOT working on his. So I need to retest on his machine when we have time.
Had the same problem, installed .NET 4.5 and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.