How can I assign the enter key
to the on_Click
event in the following code?
To make this clear I want to trigger the code inside the on_Click()
method when the enter key is pressed.
Again, I'm using the MVVMLight framework.
ViewModel
namespace MyApp.ViewModel
{
public class AppViewModel : ViewModelBase
{
public ICommand clickCommand { get; private set; }
public AppViewModel()
{
clickCommand = new RelayCommand(() => on_Click());
}
private void on_Click()
{
// button clicked
}
}
}
XAML
<Button x:Name="myButton"
Content="Click Me"
HorizontalAlignment="right"
Margin="0,84,72,0"
VerticalAlignment="Top"
Width="66" Height="25"
Command="{Binding clickCommand}" Foreground="#FFF2F5FC" BorderBrush="{x:Null}">
<Button.Background>
<SolidColorBrush Color="#FF3DA5DB"/>
</Button.Background>
</Button>