Capture keyboard event CTRL+S in WPF


I need to fire an event by pressing CTRL+s.To do this create a windows “KeyDown” event like this


<Window x:Class="Testing.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"  KeyDown="Window_KeyDown">

Now use this cs code


private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.S)
{
MessageBox.Show("user is pressed Ctrl+S");
}
}

If you have any query please leave a comment.