WPF:如果UI元素不可见,则停止绑定 [英] WPF: Stop Binding if a UI element is not visible

查看:105
本文介绍了WPF:如果UI元素不可见,则停止绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果当前不可见ui元素,可以延迟该元素的绑定吗?有时我的表单中包含一些隐藏/最小化的元素,如果它们不在屏幕上,我不希望对其进行更新。我怀疑答案是否定的,但问这个问题从来没有伤害吗?

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?

推荐答案

没有内置的方法可以执行此操作-但是您可以自己编写。

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

诀窍是将绑定包装在使用原始绑定但在其周围添加新行为的自己的标记扩展中(例如,通过设置UpdateSourceTrigger

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.

这篇关于WPF:如果UI元素不可见,则停止绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆