Wpf code behind call viewModel method
public MessageView() { InitializeComponent(); this.KeyDown += MessageView_KeyDown; } private void MessageView_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { var vm = this.DataContext as MessageViewModel; if(vm!=null) { vm.SendMessage(); ShowTextBoxContent(vm.TbText); } } } StringBuilder textBuilder = new StringBuilder(); private void ShowTextBoxContent(string msg) { textBuilder.AppendLine(msg); tbx.Text = textBuilder.ToString(); }