views:

74

answers:

2

Hi,

I have a text box declared in xaml that uses databinding to a string property. How do I disable and then re-enable binding in code?

Thanks!

A: 

I'm not sure if it would work or not, but you could try calling FrameworkElement.SetBinding(), and pass null for the second parameter.

Andy
I haven't tried it, but it's a wrapper around BindingOperations.SetBinding, which says it will throw if the binding is null. See: http://msdn.microsoft.com/en-us/library/system.windows.data.bindingoperations.setbinding.aspx
Reed Copsey
+3  A: 

You can use BindingOperations.ClearBinding to remove a binding, and BindingOperations.SetBinding to add it back in.

Reed Copsey
Looks like I can't really actually turn bindings on and off, but that seems good enough. Thanks!
Steve the Plant