gpt4 book ai didi

wpf - TextEdit_KeyDown 事件绑定(bind)到命令

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

我有一个 TextEdit 和一个像这样的按钮:

<dxe:TextEdit Text="{Binding SearchText}" Width="200" Height="25" VerticalAlignment="Center"  KeyDown="TextEdit_KeyDown" />
<Button Command="{Binding SearchCommand}" VerticalAlignment="Center" Margin="20,0,0,0" >

当用户单击按钮时,SearchCommand 会成功运行并返回结果。当用户按下 时,我希望同样的事情发生输入 .如何将 TextEdit_KeyDown 事件绑定(bind)到命令,以便获得相同的结果。

最佳答案

看看EventToCommand来自 DevExpress MVVM Framework 的行为:

查看:

<UserControl ...
DataContext="{dxmvvm:ViewModelSource Type=local:SearchViewModel}">
//...
<dxe:TextEdit Text="{Binding SearchText}" Width="200" Height="25" VerticalAlignment="Center">
<dxmvvm:Interaction.Behaviors>
<dxmvvm:EventToCommand EventName="KeyDown"
Command="{Binding SearchByKeyCommand}"
PassEventArgsToCommand="True"
>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
<Button Command="{Binding SearchCommand}" VerticalAlignment="Center" Margin="20,0,0,0" >
//...

查看型号:
[POCOViewModel]
public class SearchViewModel {
public virtual SearchText {
get ;
set;
}
public void Search() {
//...
}
public void SearchByKey(KeyEventArgs) {
Search();
}
public bool CanSearchByKey(KeyEventArgs args) {
return (args.KeyCode == Keys.Enter) && !string.IsNullOrEmpty(SearchText);
}
}

关于wpf - TextEdit_KeyDown 事件绑定(bind)到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26251946/

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