如何等待WPF绑定延迟完成 [英] How to wait for WPF Binding Delay to complete

查看:90
本文介绍了如何等待WPF绑定延迟完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ViewModel实现INotifyPropertyChanged和INotifyDataErrorInfo接口.更改属性后,验证触发,从而启用/禁用保存"按钮.

My ViewModel implements the INotifyPropertyChanged and INotifyDataErrorInfo interfaces. When the property is changed, the validation triggers, which in turn enables\disable the Save button.

由于验证"步骤非常耗时,因此我使用了延迟"绑定属性.

Because the Validation step is time consuming I've made use of the Delay binding property.

我的问题是,我可以键入所做的更改,然后在名称"属性更新之前按保存".

My problem is that I can type my changes and press Save before the 'Name' property is updated.

当我按下SaveChanges时,我想强制对TextBox.Text进行立即更新.此刻,我必须在执行之前添加一个睡眠,以确保ViewModel上发生了所有更改.

I'd like to force an immediate update on the TextBox.Text when I press SaveChanges. At the moment, I have to add a sleep before executing to ensure all changes have occurred on the ViewModel.

<TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Delay=1000}" />
<Button Command="{Binding SaveChanges}" />

有人有一些指针吗?

推荐答案

.NET 4.5以来存在BindingOperations

Since .NET 4.5 there exists BindingOperations

BindingOperations.GetSourceUpdatingBindings(this).ToList().ForEach(x => x.UpdateSource());

这篇关于如何等待WPF绑定延迟完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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