From 165fc41151219fb2b65f3ae36d518cf898669620 Mon Sep 17 00:00:00 2001 From: Zach Date: Sat, 28 Jan 2023 19:46:28 -0500 Subject: [PATCH] Updated game selector to use kebab menu --- .../GameConfiguration/LaunchWindow.xaml | 128 ++++++++++++++++-- .../GameConfiguration/LaunchWindow.xaml.cs | 19 ++- 2 files changed, 134 insertions(+), 13 deletions(-) diff --git a/CompilePalX/GameConfiguration/LaunchWindow.xaml b/CompilePalX/GameConfiguration/LaunchWindow.xaml index 16abe3db..d89fa0ca 100644 --- a/CompilePalX/GameConfiguration/LaunchWindow.xaml +++ b/CompilePalX/GameConfiguration/LaunchWindow.xaml @@ -33,20 +33,126 @@ - - - - - - - + + diff --git a/CompilePalX/GameConfiguration/LaunchWindow.xaml.cs b/CompilePalX/GameConfiguration/LaunchWindow.xaml.cs index 2030a69e..aca04225 100644 --- a/CompilePalX/GameConfiguration/LaunchWindow.xaml.cs +++ b/CompilePalX/GameConfiguration/LaunchWindow.xaml.cs @@ -145,14 +145,14 @@ public void RefreshGameConfigurationList() private void EditButton_OnClick(object sender, RoutedEventArgs e) { - var configuration = (GameConfiguration)((Button)sender).DataContext; + var configuration = (GameConfiguration)((MenuItem)sender).DataContext; int configIndex = GameConfigurationManager.GameConfigurations.IndexOf(configuration); GameConfigurationWindow.Instance.Open(configuration.Clone() as GameConfiguration, configIndex); } private async void DeleteButton_OnClick(object sender, RoutedEventArgs e) { - var configuration = (GameConfiguration)((Button)sender).DataContext; + var configuration = (GameConfiguration)((MenuItem)sender).DataContext; var dialogSettings = new MetroDialogSettings() { @@ -189,5 +189,20 @@ private void RefreshButton_OnClick(object sender, RoutedEventArgs e) GameGrid.ItemsSource = GameConfigurationManager.GameConfigurations; RefreshGameConfigurationList(); } + private void GameKebabButton_OnClick(object sender, RoutedEventArgs e) + { + if (sender is not Button button || button.ContextMenu == null) + return; + + // set placement of context menu to button instead of default behaviour of mouse position + button.ContextMenu.PlacementTarget = button; + button.ContextMenu.IsOpen = true; + e.Handled = true; + } + private void GameKebabButton_OnContextMenuOpening(object sender, ContextMenuEventArgs e) + { + // block right click context menus + e.Handled = true; + } } }