-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Two-way bindings gives 'Cannot save value from target back to source' in debug output #10
Comments
Are you using |
Yes, this is a two-way binding. |
Do you have |
Here's the repo: https://github.com/CompositionalIT/ElmishWpfSample (Note: |
I see it now and know why it's happening. It shouldn't affect any functionality but you're right about effects on performance. I will look into a way to avoid this. |
I see this in the Elmish.Samples.Counter demo, or to be exact, in my own demo where the Elmish.Samples.Counter demo source was copied, to get a start. It happens every time the slider is moved. Just mentioning it in case there's need for a repro. Error message:
|
@isaacabraham, I have one case now where Mode=TwoWay has to be set explicitly, or else it won't work. But I have also seen that in most cases it appears to be the default. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
After having looked into this a bit, it seems like the view performs an immediate This leaves me with three questions:
|
Oh, another question, perhaps the most important - can @2sComplement or anyone else answer me this: Why is the |
If I recall correctly, allowing it resulted in some undesirable view behaviour. For example, typing in an input box would be annoying, assuming you wanted characters to appear in the correct order. With each key press the view would update the text box with the old value before updating the model. |
Thanks for the quick reply! Yes, I observe the behaviour you're describing; I initially only tested with a slider. With a TextBox however, you essentially type backwards. That leaves my first three questions. |
Apologies for my absence in general lately, been very tied up on other projects. I couldn't prove any real impacts of this error. Nor do I know a way around it without somehow overriding the behaviour of WPF through perhaps some custom binding type, which is probably the route I would have taken to investigate a fix for this. Not convinced it's worth it though. |
I noticed this afternoon that on aBinding.oneWay, the getter is called 3 times per update (on a silly example involving a button that increases an integer and a textbox displaying it). I was wondering if that was due to your implementation or if it was already the case before, but I didn’t check. Is it the case you’re talking about ? Naive suggestion for the get called just after the set : would a timed out lock or mutex on TryGetMember and TrySetmember be helpful ? I’m far from my office PC right now, I can’t watch exactly what the problem is. |
@JDiLenarda it's not the same if it's a one-way binding, no. Please take a look at the SingleCounter example in the rewrite branch, TryGetMember is only called once there. If you find out why it's called three times in your example, let us know, and let us know if it's a bug or if we should make something clear in the documentation. If you can't figure it out, I can also take a repro solution, but I'm busy this week with other projects too, so I can't promise I can look at it right away. As for locking: I'm very wary of doing that due to general multithreaded complexity and other performance concerns following from that solution, and also because I'm not sure the reported error actually matters at all outside development/debugging scenarios. Thanks for the tip, though. If you have a concrete implementation and performance numbers to back it up, feel free to make a PR. :) |
Now I think about it, it’s probably because the Textbox is on Mode=TwoWay by default. I’ll check tomorrow. Edit: never mind, I was on a false lead. It is normal that the getter of Binding.oneWay is called 3 times (it is also the case on SingleCounter) : twice by UpdateModel (against the current and the new model for comparison) and once by TryGetMember, which is called only once. |
Thanks for the clarification, @JDiLenarda (didn't see your edit before now). To everyone and no-one in particular, allow me to quote my three unanswered questions lest they get lost in the thread. Perhaps @ReedCopsey knows the answer to some of these questions?
|
This should be fixed in 2.0.0-beta-10 |
On a simple two-way binding from a textbox to a string on a model, I see the following output when running: -
This doesn't crash the app, but repeated errors like these have an effort on WPF perf when they mount up.
The text was updated successfully, but these errors were encountered: