Me gustaría que el menú principal en mi aplicación WPF a comportarse como el menú principal en IE8:¿Cómo puedo alternar la visibilidad del menú principal con la tecla Alt en WPF?
- no es visible cuando se inicia la aplicación
- presionar y soltar Alt hace visible
- presionando y Alt liberando de nuevo lo hace invisible una vez más
- repetir hasta aburrido
¿Cómo puedo hacer esto? ¿Tiene que ser código?
añadido en respuesta a las respuestas enviadas, porque todavía estoy teniendo problemas:
Mi Shell de código subyacente ahora se ve así:
public partial class Shell : Window
{
public static readonly DependencyProperty IsMainMenuVisibleProperty;
static Shell()
{
FrameworkPropertyMetadata metadata = new FrameworkPropertyMetadata();
metadata.DefaultValue = false;
IsMainMenuVisibleProperty = DependencyProperty.Register(
"IsMainMenuVisible", typeof(bool), typeof(Shell), metadata);
}
public Shell()
{
InitializeComponent();
this.PreviewKeyUp += new KeyEventHandler(Shell_PreviewKeyUp);
}
void Shell_PreviewKeyUp(object sender, KeyEventArgs e)
{
if (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt)
{
if (IsMainMenuVisible == true)
IsMainMenuVisible = false;
else
IsMainMenuVisible = true;
}
}
public bool IsMainMenuVisible
{
get { return (bool)GetValue(IsMainMenuVisibleProperty); }
set { SetValue(IsMainMenuVisibleProperty, value); }
}
}
Usted quiere imitar Internet Explorer ...? –
Intento mantener mis aplicaciones consistentes con lo que esperan los usuarios, así que sí. :-) – serialhobbyist
También podría ser responsable de la tecla F10 que desencadena el mismo comportamiento por coherencia. – genus