2014-10-08 137 views
1

我有一个文本编辑和按钮这样的:TextEdit_KeyDown事件绑定到一个命令

<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工程成功并返回resulsts。我想当用户按下输入时发生同样的事情。我怎样才能将TextEdit_KeyDown事件绑定到一个命令,以便得到相同的结果。

回答

2

传输距离DevExpress MVVM Framework看看在EventToCommand行为,总是发送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" > 
    //... 

ViewModel:

[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); 
    } 
} 
0
if (e.KeyCode == Keys.Enter) 
    { 
     //Do your stuff 

    } 

e是打电话时,所以你必须要看到什么是可变

相关问题