2024-05-23 19:31:20 -07:00
|
|
|
|
using System.ComponentModel;
|
2024-05-23 06:24:22 -07:00
|
|
|
|
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
|
{
|
|
|
|
|
public static class ContextMenuExtension
|
|
|
|
|
{
|
|
|
|
|
public static void OpenContextMenu(this Control control, ContextMenu menu)
|
|
|
|
|
{
|
2024-06-06 00:31:02 -07:00
|
|
|
|
if (menu == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-05-23 06:24:22 -07:00
|
|
|
|
menu.PlacementTarget = control;
|
|
|
|
|
menu.Closing += OnContextMenuClosing; // Clear context menu because it is dynamic.
|
|
|
|
|
|
|
|
|
|
control.ContextMenu = menu;
|
|
|
|
|
control.ContextMenu.Open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void OnContextMenuClosing(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender is ContextMenu menu && menu.PlacementTarget != null)
|
|
|
|
|
menu.PlacementTarget.ContextMenu = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|