|
|
@ -269,7 +269,43 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
control ??= _attachedControls![0]; |
|
|
control ??= _attachedControls![0]; |
|
|
|
|
|
Open(control, PlacementTarget ?? control); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Closes the menu.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void Close() |
|
|
|
|
|
{ |
|
|
|
|
|
if (!IsOpen) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_popup != null && _popup.IsVisible) |
|
|
|
|
|
{ |
|
|
|
|
|
_popup.IsOpen = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ISetterValue.Initialize(ISetter setter) |
|
|
|
|
|
{ |
|
|
|
|
|
// ContextMenu can be assigned to the ContextMenu property in a setter. This overrides
|
|
|
|
|
|
// the behavior defined in Control which requires controls to be wrapped in a <template>.
|
|
|
|
|
|
if (!(setter is Setter s && s.Property == ContextMenuProperty)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidOperationException( |
|
|
|
|
|
"Cannot use a control as a Setter value. Wrap the control in a <Template>."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override IItemContainerGenerator CreateItemContainerGenerator() |
|
|
|
|
|
{ |
|
|
|
|
|
return new MenuItemContainerGenerator(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void Open(Control control, Control placementTarget) |
|
|
|
|
|
{ |
|
|
if (IsOpen) |
|
|
if (IsOpen) |
|
|
{ |
|
|
{ |
|
|
return; |
|
|
return; |
|
|
@ -286,7 +322,6 @@ namespace Avalonia.Controls |
|
|
PlacementGravity = PlacementGravity, |
|
|
PlacementGravity = PlacementGravity, |
|
|
PlacementMode = PlacementMode, |
|
|
PlacementMode = PlacementMode, |
|
|
PlacementRect = PlacementRect, |
|
|
PlacementRect = PlacementRect, |
|
|
PlacementTarget = PlacementTarget ?? control, |
|
|
|
|
|
IsLightDismissEnabled = true, |
|
|
IsLightDismissEnabled = true, |
|
|
OverlayDismissEventPassThrough = true, |
|
|
OverlayDismissEventPassThrough = true, |
|
|
WindowManagerAddShadowHint = WindowManagerAddShadowHint, |
|
|
WindowManagerAddShadowHint = WindowManagerAddShadowHint, |
|
|
@ -302,11 +337,7 @@ namespace Avalonia.Controls |
|
|
((ISetLogicalParent)_popup).SetParent(control); |
|
|
((ISetLogicalParent)_popup).SetParent(control); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (PlacementTarget is null && _popup.PlacementTarget != control) |
|
|
_popup.PlacementTarget = placementTarget; |
|
|
{ |
|
|
|
|
|
_popup.PlacementTarget = control; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_popup.Child = this; |
|
|
_popup.Child = this; |
|
|
IsOpen = true; |
|
|
IsOpen = true; |
|
|
_popup.IsOpen = true; |
|
|
_popup.IsOpen = true; |
|
|
@ -318,38 +349,6 @@ namespace Avalonia.Controls |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Closes the menu.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void Close() |
|
|
|
|
|
{ |
|
|
|
|
|
if (!IsOpen) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_popup != null && _popup.IsVisible) |
|
|
|
|
|
{ |
|
|
|
|
|
_popup.IsOpen = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ISetterValue.Initialize(ISetter setter) |
|
|
|
|
|
{ |
|
|
|
|
|
// ContextMenu can be assigned to the ContextMenu property in a setter. This overrides
|
|
|
|
|
|
// the behavior defined in Control which requires controls to be wrapped in a <template>.
|
|
|
|
|
|
if (!(setter is Setter s && s.Property == ContextMenuProperty)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new InvalidOperationException( |
|
|
|
|
|
"Cannot use a control as a Setter value. Wrap the control in a <Template>."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override IItemContainerGenerator CreateItemContainerGenerator() |
|
|
|
|
|
{ |
|
|
|
|
|
return new MenuItemContainerGenerator(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void PopupOpened(object sender, EventArgs e) |
|
|
private void PopupOpened(object sender, EventArgs e) |
|
|
{ |
|
|
{ |
|
|
_previousFocus = FocusManager.Instance?.Current; |
|
|
_previousFocus = FocusManager.Instance?.Current; |
|
|
@ -403,7 +402,7 @@ namespace Avalonia.Controls |
|
|
if (contextMenu.CancelOpening()) |
|
|
if (contextMenu.CancelOpening()) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
contextMenu.Open(control); |
|
|
contextMenu.Open(control, e.Source as Control ?? control); |
|
|
e.Handled = true; |
|
|
e.Handled = true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|