Wpf TextEdit_KeyDown事件绑定到命令

Wpf TextEdit_KeyDown事件绑定到命令,wpf,mvvm,binding,devexpress,mvvm-light,Wpf,Mvvm,Binding,Devexpress,Mvvm Light,我有一个文本编辑和如下按钮: <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" > 当用户单击该按

我有一个文本编辑和如下按钮:

<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将成功运行并返回结果。我希望当用户按SESEnter时也会发生同样的情况。如何将TextEdit_KeyDown事件绑定到命令,以便获得相同的结果

 if (e.KeyCode == Keys.Enter)
    {
        //Do your stuff

    }
e是调用时始终传输的EventArg,因此您必须查看变量中传输的内容查看以下行为:

查看:

<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);
    }
}