|
|
@ -4,6 +4,7 @@ using System.ComponentModel; |
|
|
using Avalonia.Controls.Generators; |
|
|
using Avalonia.Controls.Generators; |
|
|
using Avalonia.Controls.Platform; |
|
|
using Avalonia.Controls.Platform; |
|
|
using Avalonia.Controls.Primitives; |
|
|
using Avalonia.Controls.Primitives; |
|
|
|
|
|
using Avalonia.Controls.Primitives.PopupPositioning; |
|
|
using Avalonia.Controls.Templates; |
|
|
using Avalonia.Controls.Templates; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Input; |
|
|
using Avalonia.Interactivity; |
|
|
using Avalonia.Interactivity; |
|
|
@ -19,11 +20,6 @@ namespace Avalonia.Controls |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public class ContextMenu : MenuBase, ISetterValue |
|
|
public class ContextMenu : MenuBase, ISetterValue |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="PlacementMode"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<PlacementMode> PlacementModeProperty = |
|
|
|
|
|
Popup.PlacementModeProperty.AddOwner<ContextMenu>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="HorizontalOffset"/> property.
|
|
|
/// Defines the <see cref="HorizontalOffset"/> property.
|
|
|
@ -37,6 +33,30 @@ namespace Avalonia.Controls |
|
|
public static readonly StyledProperty<double> VerticalOffsetProperty = |
|
|
public static readonly StyledProperty<double> VerticalOffsetProperty = |
|
|
Popup.VerticalOffsetProperty.AddOwner<ContextMenu>(); |
|
|
Popup.VerticalOffsetProperty.AddOwner<ContextMenu>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="PlacementAnchor"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<PopupAnchor> PlacementAnchorProperty = |
|
|
|
|
|
Popup.PlacementAnchorProperty.AddOwner<ContextMenu>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="PlacementGravity"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<PopupGravity> PlacementGravityProperty = |
|
|
|
|
|
Popup.PlacementGravityProperty.AddOwner<ContextMenu>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="PlacementMode"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<PlacementMode> PlacementModeProperty = |
|
|
|
|
|
Popup.PlacementModeProperty.AddOwner<ContextMenu>(); |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Defines the <see cref="PlacementRect"/> property.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly StyledProperty<Rect?> PlacementRectProperty = |
|
|
|
|
|
AvaloniaProperty.Register<Popup, Rect?>(nameof(PlacementRect)); |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Defines the <see cref="PlacementTarget"/> property.
|
|
|
/// Defines the <see cref="PlacementTarget"/> property.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -77,16 +97,7 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets or sets the placement mode of the popup in relation to the <see cref="PlacementTarget"/>.
|
|
|
/// Gets or sets the Horizontal offset of the context menu in relation to the <see cref="PlacementTarget"/>.
|
|
|
/// </summary>
|
|
|
|
|
|
public PlacementMode PlacementMode |
|
|
|
|
|
{ |
|
|
|
|
|
get { return GetValue(PlacementModeProperty); } |
|
|
|
|
|
set { SetValue(PlacementModeProperty, value); } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the Horizontal offset of the popup in relation to the <see cref="PlacementTarget"/>
|
|
|
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public double HorizontalOffset |
|
|
public double HorizontalOffset |
|
|
{ |
|
|
{ |
|
|
@ -95,7 +106,7 @@ namespace Avalonia.Controls |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets or sets the Vertical offset of the popup in relation to the <see cref="PlacementTarget"/>
|
|
|
/// Gets or sets the Vertical offset of the popup in relation to the <see cref="PlacementTarget"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
public double VerticalOffset |
|
|
public double VerticalOffset |
|
|
{ |
|
|
{ |
|
|
@ -103,6 +114,52 @@ namespace Avalonia.Controls |
|
|
set { SetValue(VerticalOffsetProperty, value); } |
|
|
set { SetValue(VerticalOffsetProperty, value); } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the anchor point on the <see cref="PlacementRect"/> when <see cref="PlacementMode"/>
|
|
|
|
|
|
/// is <see cref="PlacementMode.AnchorAndGravity"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public PopupAnchor PlacementAnchor |
|
|
|
|
|
{ |
|
|
|
|
|
get { return GetValue(PlacementAnchorProperty); } |
|
|
|
|
|
set { SetValue(PlacementAnchorProperty, value); } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a value which defines in what direction the context menu should open
|
|
|
|
|
|
/// when <see cref="PlacementMode"/> is <see cref="PlacementMode.AnchorAndGravity"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public PopupGravity PlacementGravity |
|
|
|
|
|
{ |
|
|
|
|
|
get { return GetValue(PlacementGravityProperty); } |
|
|
|
|
|
set { SetValue(PlacementGravityProperty, value); } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the placement mode of the context menu in relation to the<see cref="PlacementTarget"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public PlacementMode PlacementMode |
|
|
|
|
|
{ |
|
|
|
|
|
get { return GetValue(PlacementModeProperty); } |
|
|
|
|
|
set { SetValue(PlacementModeProperty, value); } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the the anchor rectangle within the parent that the popup will be placed
|
|
|
|
|
|
/// relative to when <see cref="PlacementMode"/> is <see cref="PlacementMode.AnchorAndGravity"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// The placement rect defines a rectangle relative to <see cref="PlacementTarget"/> around
|
|
|
|
|
|
/// which the popup will be opened, with <see cref="PlacementAnchor"/> determining which edge
|
|
|
|
|
|
/// of the placement target is used.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// If unset, the anchor rectangle will be the bounds of the <see cref="PlacementTarget"/>.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public Rect? PlacementRect |
|
|
|
|
|
{ |
|
|
|
|
|
get { return GetValue(PlacementRectProperty); } |
|
|
|
|
|
set { SetValue(PlacementRectProperty, value); } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets or sets the control that is used to determine the popup's position.
|
|
|
/// Gets or sets the control that is used to determine the popup's position.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -187,7 +244,10 @@ namespace Avalonia.Controls |
|
|
{ |
|
|
{ |
|
|
HorizontalOffset = HorizontalOffset, |
|
|
HorizontalOffset = HorizontalOffset, |
|
|
VerticalOffset = VerticalOffset, |
|
|
VerticalOffset = VerticalOffset, |
|
|
|
|
|
PlacementAnchor = PlacementAnchor, |
|
|
|
|
|
PlacementGravity = PlacementGravity, |
|
|
PlacementMode = PlacementMode, |
|
|
PlacementMode = PlacementMode, |
|
|
|
|
|
PlacementRect = PlacementRect, |
|
|
PlacementTarget = PlacementTarget ?? control, |
|
|
PlacementTarget = PlacementTarget ?? control, |
|
|
StaysOpen = false |
|
|
StaysOpen = false |
|
|
}; |
|
|
}; |
|
|
|