当属性更改时,有没有一种方法执行命令,指定的绑定延迟?
作为一个例子,让我们使用CheckBox,它具有属性Iscury,延迟= 1000(1秒),以及当Iscury属性发生变化时调用的Command:
MainWindow.xaml:
<CheckBox Command="{Binding Command}"
Content="Hello"
IsChecked="{Binding IsChecked, Delay=1000}" />
MainWindow.xaml.cs:
private bool _isChecked;
public bool IsChecked
{
get { return _isChecked; }
set
{
if (_isChecked != value)
{
_isChecked = value;
OnPropertyChanged();
MessageBox.Show("Property Changed");
}
}
}
public ICommand Command { get; } = new RelayCommand(obj => MessageBox.Show("Command Invoked"));
当点击复选框时,首先调用MessageBox.Show("命令已删除"),然后调用MessageBox.Show("属性已更改");
最终输出:
"Command Invoked" -\> after 1 sec delay -\> "Property Changed"