WPF TextBox按回车键执行
WPF TextBox按回车键执行,示例代码如下:
<TextBox x:Name="tbSN" Text="{Binding materialModel.SN, Mode=TwoWay}" Width="356">
<TextBox.InputBindings>
<KeyBinding Command="{Binding QueryCommand}" Key="Enter" CommandParameter="{Binding ElementName=tbSN, Path=Text}"/>
</TextBox.InputBindings>
</TextBox>
MVVM命令,示例代码如下:
/// <summary>
/// 查询命令
/// </summary>
private DelegateCommand<string> _queryCommand;
public DelegateCommand<string> QueryCommand
{
get
{
if (_queryCommand == null)
{
_queryCommand = new DelegateCommand<string>(QueryCommandExecuted);
}
return _queryCommand;
}
}
private void QueryCommandExecuted(string sn)
{
}

浙公网安备 33010602011771号