Browse Source

contextmenu sub menus now close when context is lost.

pull/405/head
danwalmsley 11 years ago
parent
commit
13f0d4d530
  1. 21
      src/Perspex.Controls/ContextMenu.cs
  2. 2
      src/Perspex.Themes.Default/ContextMenu.paml

21
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
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}"

Loading…
Cancel
Save