views:

33

answers:

2

Today I faced a problem which reminded me of bindings being detached automatically in some cases. I am not sure but here is the scenario -

I attach a menu item bound to a property(implementing INotifyPropertyChanged), like this -

IsChecked="{Binding Path=DisplayLongUnit, Mode=TwoWay}"

Now in its checked event hander I update its IsChecked value after checking some condition like this -

If( condition == true){menuItem.IsChecked = true}

Now will the binding be still attached or it will get lost? (I remember reading somewhere that it will be lost).

Are there any scenarios in which bindings will be detached automatically?

One I could find out is mentioned here -

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/08d6e4c4-47ab-44f3-b19a-c0ab872fb1a8

A: 

Have you tried a two-way binding?

IsChecked="{Binding Path=DisplayLongUnit, Mode=TwoWay}"
rdkleine
A: 

A more specific example of what your problem is is here:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/4165daed-2eaf-450b-a082-63d79ff9fd3e

You might want to make the binding mode two way (that way your property will be updated too, and I don't know what the default is for IsChecked, but it's always best to be explicit) or simply change the DisplayLongUnit property in stead of the IsChecked property.

Carrotman
Thanks for your response Carrotman but I am not facing any issue with the binding example I provided in my question. The question is about binding getting reset or lost in some scenarios.
akjoshi