views:

216

answers:

3

Can i delay binding of a ui element if the element is not currently visible. Sometimes i have a form that has some hidden/minimised elements, i would like to not update them if they are not on the screen. I suspect the answer is no, but it never hurts to ask?

+1  A: 

The answer is no because the binding might be cause of making an element visible again. So if binding did not work on hidden controls it would not allow the binding to make it visible again.

Phil Wright
sounds logical.
Aran Mulholland
+1  A: 

There is no built in way to do this - but you can write it yourself.

The trick is to wrap binding in your own markup extension that uses the original binding but adds new behavior around it (for example, by setting UpdateSourceTrigger to Explicit when you don't want the binding to work.

Here's an example (that delays the binding's data transfer):

http://www.paulstovell.com/wpf-delaybinding

Now, there are a lot of possible edge conditions with disabling bindings for invisible controls, especially around showing and hiding controls, so I wouldn't write a generic extension for this - but maybe in your specific application this can be useful.

Nir
thats wierd, i wrote a similar thing - http://www.codeproject.com/KB/WPF/DelayedBindingTextBox.aspx
Aran Mulholland
+1  A: 

For a workaround I have a binding to the visibility of the object, when the object is set to visible, the property triggers the construction of the element behind it which have a binding via a ContentPresenter.

Eduardo Molteni