WPF: Stop Binding if a UI element is not visible

后端 未结 5 484
滥情空心
滥情空心 2021-02-05 06:16

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

5条回答
  •  终归单人心
    2021-02-05 06:32

    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.

提交回复
热议问题