I have a seemingly simple task that gives me headaches and will be very grateful for the help.
I want to bind two booleans to the IsChecked property of two RadioButton s using the same GroupName (so only one of them is checked at a time).
The problem I am facing is that when the ContentPresenter Content is about to change (via binding to the SelectedItem ComboBox), the current content gets a call to the setter property with the value of the same property, but from the view model, which is about to will become new content. (!) The end result is a change in the presentation model, despite the absence of a click on the RadioButton associated with the property in question.
I put together an example application that shows the problem. To play, run the application and follow these steps:
- Select "One" in the combobox => MyPropery field, MyProperty2 - no.
- Select "Three" in the combobox => MyPropery field, MyProperty2 - no.
- If you select Three, choose MyProperty2> MyProperty2 (also indicated in the debug output window).
- Select "One" in the combobox => MyPropery field, MyProperty2 - no. Notice how the debug window shows how MyProperty2 of the Three object is set to false here.
- Select "Three" in combobox => Now none of the Radiobuttons are tested (due to # 4).
If between # 3 and # 4 you first select “Two” in the drop-down list so that ContentPresenter displays a different view (selected using the DataTemplate), the problem does not appear !?
Can someone explain why the property was set in step 4 when exchanging views using ContentPresenter and what can be done with it?
source share