Browse Source

addressed issues in PR# 405

pull/405/head
danwalmsley 11 years ago
parent
commit
cd01ca61c9
  1. 43
      src/Perspex.Controls/ContextMenu.cs
  2. 5
      src/Perspex.Themes.Default/ContextMenu.paml

43
src/Perspex.Controls/ContextMenu.cs

@ -11,24 +11,13 @@
{ {
private bool _isOpen; private bool _isOpen;
/// <summary>
/// Defines the ContextMenu.Menu attached property.
/// </summary>
//public static readonly AttachedProperty<object> ContextMenuProperty =
// PerspexProperty.RegisterAttached<ContextMenu, Control, object>("Menu");
/// <summary> /// <summary>
/// The popup window used to display the active context menu. /// The popup window used to display the active context menu.
/// </summary> /// </summary>
private static PopupRoot s_popup; private static PopupRoot s_popup;
/// <summary> /// <summary>
/// The control that the currently visible context menu is attached to. /// Initializes static members of the <see cref="ContextMenu"/> class.
/// </summary>
private static Control s_current;
/// <summary>
/// Initializes static members of the <see cref="ToolTip"/> class.
/// </summary> /// </summary>
static ContextMenu() static ContextMenu()
{ {
@ -37,28 +26,6 @@
MenuItem.ClickEvent.AddClassHandler<ContextMenu>(x => x.OnContextMenuClick); MenuItem.ClickEvent.AddClassHandler<ContextMenu>(x => x.OnContextMenuClick);
} }
/// <summary>
/// Gets the value of the ToolTip.Tip attached property.
/// </summary>
/// <param name="element">The control to get the property from.</param>
/// <returns>
/// The content to be displayed in the control's tooltip.
/// </returns>
public static object GetContextMenu(Control element)
{
return element.GetValue(ContextMenuProperty);
}
/// <summary>
/// Sets the value of the ToolTip.Tip attached property.
/// </summary>
/// <param name="element">The control to get the property from.</param>
/// <param name="value">The content to be displayed in the control's tooltip.</param>
public static void SetContextMenu(Control element, object value)
{
element.SetValue(ContextMenuProperty, value);
}
/// <summary> /// <summary>
/// called when the <see cref="ContextMenuProperty"/> property changes on a control. /// called when the <see cref="ContextMenuProperty"/> property changes on a control.
/// </summary> /// </summary>
@ -110,7 +77,7 @@
} }
/// <summary> /// <summary>
/// Shows a tooltip for the specified control. /// Shows a context menu for the specified control.
/// </summary> /// </summary>
/// <param name="control">The control.</param> /// <param name="control">The control.</param>
private static void Show(Control control) private static void Show(Control control)
@ -121,7 +88,7 @@
{ {
s_popup = new PopupRoot s_popup = new PopupRoot
{ {
Content = new ToolTip(), Content = new ContentControl(),
}; };
((ISetLogicalParent)s_popup).SetParent(control); ((ISetLogicalParent)s_popup).SetParent(control);
@ -130,12 +97,10 @@
var cp = MouseDevice.Instance?.GetPosition(control); var cp = MouseDevice.Instance?.GetPosition(control);
var position = control.PointToScreen(cp ?? new Point(0, 0)); var position = control.PointToScreen(cp ?? new Point(0, 0));
((ToolTip)s_popup.Content).Content = GetContextMenu(control); ((ContentControl)s_popup.Content).Content = control.ContextMenu;
s_popup.Position = position; s_popup.Position = position;
s_popup.Show(); s_popup.Show();
s_current = control;
control.ContextMenu._isOpen = true; control.ContextMenu._isOpen = true;
} }
} }

5
src/Perspex.Themes.Default/ContextMenu.paml

@ -1,5 +1,8 @@
<Style xmlns="https://github.com/perspex" Selector="ContextMenu"> <Style xmlns="https://github.com/perspex" Selector="ContextMenu">
<Setter Property="Template"> <Setter Property="BorderBrush" Value="Gray"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="4,2"/>
<Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Border Background="{TemplateBinding Background}" <Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"

Loading…
Cancel
Save