gpt4 book ai didi

.net - WPF基于属性更改键绑定(bind)的绑定(bind)命令?

转载 作者:行者123 更新时间:2023-12-03 10:26:29 24 4
gpt4 key购买 nike

我有一个要绑定(bind) Escape key 的 xaml 窗口根据 bool 属性的值,在我的 View 模型中使用不同的命令。
IsSearching == true , 绑定(bind)到 CancelSearch 命令
IsSearching == false ,绑定(bind)到关闭命令。

有没有办法在没有代码的情况下做到这一点?

最佳答案

<Window>
<Window.InputBindings>
<KeyBinding Command="{Binding SomeCommand}" Key="F5"/>
</Window.InputBindings>
</Window>

This is a workaround


private ICommand someCommand;
public ICommand SomeCommand
{
get
{
return someCommand
?? (someCommand = new ActionCommand(() =>
{

if(IsSearching)
OnCancelExecute();
else
OnCloseExecute();
}));
}
}

关于.net - WPF基于属性更改键绑定(bind)的绑定(bind)命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41756863/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com