mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
fix: context menu did NOT closed after its placement target being recycled (#140)
This commit is contained in:
parent
e9208ef112
commit
0dea7ed0e2
11 changed files with 54 additions and 38 deletions
25
src/Views/ContextMenuExtension.cs
Normal file
25
src/Views/ContextMenuExtension.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public static class ContextMenuExtension
|
||||
{
|
||||
public static void OpenContextMenu(this Control control, ContextMenu menu)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue