且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.Net 4.0 中 .Net 4.5 绑定的延迟属性

更新时间:2022-06-06 02:25:58

我会创建一个 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.