Browse Source

contextmenu sub menus now close when context is lost.

danwalmsley 9 years ago
parent
commit
13f0d4d530
2 changed files with 19 additions and 4 deletions
  1. 17 4
      src/Perspex.Controls/ContextMenu.cs
  2. 2 0
      src/Perspex.Themes.Default/ContextMenu.paml

+ 17 - 4
src/Perspex.Controls/ContextMenu.cs

@@ -61,10 +61,7 @@
         /// </summary>
         public void Hide()
         {
-            foreach (MenuItem i in this.GetLogicalChildren())
-            {
-                i.IsSubMenuOpen = false;
-            }
+            
 
             if (_popup != null && _popup.IsVisible)
             {
@@ -91,6 +88,8 @@
                         PlacementTarget = control,
                         StaysOpen = false                                         
                     };
+
+                    _popup.Closed += PopupClosed;
                 }
                  
                 ((ISetLogicalParent)_popup).SetParent(control);
@@ -102,6 +101,20 @@
             }
         }
 
+        private static void PopupClosed(object sender, EventArgs e)
+        {
+            var contextMenu = (sender as Popup)?.Child as ContextMenu;
+
+            if (contextMenu != null)
+            {
+                foreach (MenuItem i in contextMenu.GetLogicalChildren())
+                {
+                    i.IsSubMenuOpen = false;
+                }
+
+                contextMenu._isOpen = false;
+            }
+        }
 
         private void PopupOpened(object sender, EventArgs e)
         {

+ 2 - 0
src/Perspex.Themes.Default/ContextMenu.paml

@@ -2,6 +2,8 @@
     <Setter Property="BorderBrush" Value="Gray"/>
     <Setter Property="BorderThickness" Value="1"/>
     <Setter Property="Padding" Value="4,2"/>
+    <Setter Property="FontSize" Value="12" />
+    <Setter Property="FontWeight" Value="Normal" />
     <Setter Property="Template">
     <ControlTemplate>
       <Border Background="{TemplateBinding Background}"