.Net 4.0 中 .Net 4.5 绑定的延迟属性 [英] Delay property on Binding from .Net 4.5 in .Net 4.0

查看:33
本文介绍了.Net 4.0 中 .Net 4.5 绑定的延迟属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 .Net 4.5 实现 Delay 属性(描述 此处) 关于 .Net 4.0 中的绑定?

How can I implement Delay property from .Net 4.5 (described here) on binding in .Net 4.0?

我知道我不能从 BindingBase 继承,因为 ProvideValue 是密封的.

I know I cannot inherit from BindingBase as ProvideValue is sealed.

我可以实现 MarkupExtension,但这意味着我现在必须重写 BindingExtension 中的所有属性,还有其他方法吗?

I could implement MarkupExtension but it means I now have to rewrite all properties from BindingExtension is there any other way?

推荐答案

我会创建一个 AttachedProperty 来指定延迟的时间量.AttachedProperty 将在绑定值更改时启动(或重置)计时器,并在达到指定的时间量时手动更新绑定源.

I would create an AttachedProperty that specifies the amount of time to Delay. The AttachedProperty would start (or reset) a timer when the bound value changes, and would manually update the bound source when the specified amount of time gets reached.

您可以使用以下内容更新源绑定:

You can use the following to update the source binding:

BindingOperations.GetBindingExpressionBase(
    dependencyObject, dependencyProperty).UpdateSource();

编辑

我今天正在修复一些旧代码中的错误,并注意到它使用附加行为实现了延迟的属性更改通知.我想到了这个问题,所以按照我在代码中评论的链接,发现自己遇到了我不久前在 SO 上发布的关于 延迟绑定.最重要的答案是我目前实现的一个,它是一些附加属性,在 X 毫秒过去后更新绑定的源.

I was fixing a bug in some old code today and noticed it implemented a delayed property change notification using an Attached Behavior. I thought of this question, so followed the link that I had commented in the code, and found myself at a question I had posted a while ago on SO about delaying a binding. The top answer is the one I have implemented currently, which is some attached properties that updates the source of a binding after X milliseconds have passed.

这篇关于.Net 4.0 中 .Net 4.5 绑定的延迟属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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