Sounds like you want KeyBinding (aka Hotkey, aka keyboard shortcut)
Have a look at the solutions to this CP post
How to Create Short Cut Keys in WPF MVVM pattern[
^]
Reference Documentation
here [
^]
Basically bind a KeyGesture to the button click in your XAML. I would probably combine those two methods into one though
private void Button_Click(object sender, RoutedEventArgs e)
{
HideMyObject(linevertical);
HideMyObject(lineo);
}
private void HideMyObject(object myObject)
{
if (myObject.Visibility == Visibility.Hidden)
{
myObject.Visibility = Visibility.Visible;
}
else
{
myObject.Visibility = Visibility.Hidden;
}
}
Edit - OP does not want to use binding. Try this instead
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.A)
{
HideMyObject(linevertical);
HideMyObject(lineo);
}
}
Note this would do the hiding if
Ctrl+A is used. It's a bad idea to just the A-key unless there is absolutely never going to be any keyboard input to the window.