- CatBytesAndCoffee
- Posts: 12
- Joined:
RadioButton binding behavior; getters not always called
Scenario: 2 RadioButtons, each bound to a different view model property. The RadioButtons are in an edit panel control. The control is Collapsed when not in use, and when it is needed the DataContext for the control is set to a new view model object and then the control is made Visible.
There are 2 apps, the real one and a repro app to try to repro the problem (which I could not).
Repro app:
* Running in Blend: the getter is called for each bound property once after setting the DataContext, and this behavior is consistent. As you change from one edit control display to another the getters are always called once, and are consistently called no matter how many times the controls are displayed.
* Running in Unity: the getter is called twice (at least) for each bound property after setting the DataContext, and this behavior is also consistent when changing the displayed controls.[/list]
Real app:
* Running in Blend: same behavior as the repro app; getter is called once consistently.
* Running in Unity: this is where things go off the rails, and is why I created the repro app which does not repro the behavior that I see in the real app. When displaying the control the first time, it behaves as expected and the getters are both called (twice, but that's consistent with the repro app). After that, however, only the getter for the first declared radio button gets called (also twice) when the DataContext is changed. I can swap the radio buttons and the same thing happens. If I declare a radio group then at some point neither getter is called when the DataContext is changed.
There is not a problem in detecting that the DataContext changed because there is also a string property on the DataContext and the displayed value changes correctly.
Since I can't repro this it's not a bug, but if anyone has any clue as to what's potentially going on I'd love to hear it.
Notes:
1. The app is more complex than described, but the repro app replicates the complexity.
2. I noticed the behavior first when using an IValueConverter, and switched to using properties while trying to figure out what was/wasn't happening.
There are 2 apps, the real one and a repro app to try to repro the problem (which I could not).
Repro app:
* Running in Blend: the getter is called for each bound property once after setting the DataContext, and this behavior is consistent. As you change from one edit control display to another the getters are always called once, and are consistently called no matter how many times the controls are displayed.
* Running in Unity: the getter is called twice (at least) for each bound property after setting the DataContext, and this behavior is also consistent when changing the displayed controls.[/list]
Real app:
* Running in Blend: same behavior as the repro app; getter is called once consistently.
* Running in Unity: this is where things go off the rails, and is why I created the repro app which does not repro the behavior that I see in the real app. When displaying the control the first time, it behaves as expected and the getters are both called (twice, but that's consistent with the repro app). After that, however, only the getter for the first declared radio button gets called (also twice) when the DataContext is changed. I can swap the radio buttons and the same thing happens. If I declare a radio group then at some point neither getter is called when the DataContext is changed.
There is not a problem in detecting that the DataContext changed because there is also a string property on the DataContext and the displayed value changes correctly.
Since I can't repro this it's not a bug, but if anyone has any clue as to what's potentially going on I'd love to hear it.
Notes:
1. The app is more complex than described, but the repro app replicates the complexity.
2. I noticed the behavior first when using an IValueConverter, and switched to using properties while trying to figure out what was/wasn't happening.
Last edited by CatBytesAndCoffee on 28 Aug 2024, 18:07, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 3112
- Joined:
Re: RadioButton binding behavior; getters not always called
I guess you have a binding to the RadioButton IsChecked property, is that binding in TwoWay mode? Using one way bindings has problems now: https://www.noesisengine.com/bugs/view.php?id=3429, because as soon as you click the radio buttons, the binding will be removed and the viewmodel won't be updated.
If that is not the case, please create a ticket about this issue in our bugtracker.
If that is not the case, please create a ticket about this issue in our bugtracker.
- CatBytesAndCoffee
- Posts: 12
- Joined:
Re: RadioButton binding behavior; getters not always called
Thanks for that!! That sounds exactly like the problem. I hadn't set up two-way because I wanted to get the one-way sorted out first.
Note to myself: don't just search the forum; search the bug reports.
Note to myself: don't just search the forum; search the bug reports.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests