是否有最好的方法手动禁用和重新启用绑定的按钮
本文关键字:新启用 启用 绑定 按钮 方法 是否 | 更新日期: 2023-09-27 18:13:13
在我的ViewModel中我有以下方法:
public async Task<Boolean> DoSomething(Button sender)
{
Binding binding = sender.GetBindingExpression(Button.IsEnabledProperty).ParentBinding;
sender.IsEnabled = false;
DoFastStuffs();
await Task.Delay(250);
sender.SetBinding(Button.IsEnabledProperty, binding);
return true;
}
有更好的方法吗?因为我注意到,手动设置属性而不将绑定保存在某个地方,将永远删除XAML对象中的实际绑定。
编辑:这是我的按钮:<Button IsEnabled="{Binding Converter={StaticResource ObjectToBooleanConverter}, ElementName=ComboBox, Path=SelectedItem}"/>
为什么不绑定按钮的Command属性呢?实现iccommand还将为您提供在UI控件上启用/禁用操作(几乎)免费使用CanExecute()功能来检查您的ComboBox的选中项…