Browse Source

Add docs and clean up

pull/5682/head
amwx 5 years ago
parent
commit
ca8d70844f
  1. 6
      src/Avalonia.Controls/Button.cs
  2. 16
      src/Avalonia.Controls/Flyouts/Flyout.cs
  3. 47
      src/Avalonia.Controls/Flyouts/FlyoutBase.cs
  4. 6
      src/Avalonia.Controls/Flyouts/FlyoutPlacementMode.cs
  5. 6
      src/Avalonia.Controls/Flyouts/FlyoutPresenter.cs
  6. 15
      src/Avalonia.Controls/Flyouts/MenuFlyout.cs

6
src/Avalonia.Controls/Button.cs

@ -79,6 +79,9 @@ namespace Avalonia.Controls
public static readonly StyledProperty<bool> IsPressedProperty =
AvaloniaProperty.Register<Button, bool>(nameof(IsPressed));
/// <summary>
/// Defines the <see cref="Flyout"/> property
/// </summary>
public static readonly DirectProperty<Button, FlyoutBase> FlyoutProperty =
AvaloniaProperty.RegisterDirect<Button, FlyoutBase>(nameof(Flyout),
x => x.Flyout, (x, v) => x.Flyout = v);
@ -175,6 +178,9 @@ namespace Avalonia.Controls
private set { SetValue(IsPressedProperty, value); }
}
/// <summary>
/// Gets or sets the Flyout that should be shown with this button
/// </summary>
public FlyoutBase Flyout
{
get => _flyout;

16
src/Avalonia.Controls/Flyouts/Flyout.cs

@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Primitives;
using Avalonia.Metadata;
using Avalonia.Styling;
#nullable enable
@ -12,13 +7,22 @@ namespace Avalonia.Controls
{
public class Flyout : FlyoutBase
{
/// <summary>
/// Defines the <see cref="Content"/> property
/// </summary>
public static readonly StyledProperty<object> ContentProperty =
AvaloniaProperty.Register<Flyout, object>(nameof(Content));
/// <summary>
/// Gets the Classes collection to applied to the FlyoutPresenter this Flyout is hosting
/// </summary>
public Classes? FlyoutPresenterClasses => _classes ??= new Classes();
private Classes? _classes;
/// <summary>
/// Gets or sets the content to display in this flyout
/// </summary>
[Content]
public object Content
{

47
src/Avalonia.Controls/Flyouts/FlyoutBase.cs

@ -15,20 +15,35 @@ namespace Avalonia.Controls.Primitives
Control.ContextFlyoutProperty.Changed.Subscribe(OnContextFlyoutPropertyChanged);
}
/// <summary>
/// Defines the <see cref="IsOpen"/> property
/// </summary>
private static readonly DirectProperty<FlyoutBase, bool> IsOpenProperty =
AvaloniaProperty.RegisterDirect<FlyoutBase, bool>(nameof(IsOpen),
x => x.IsOpen);
/// <summary>
/// Defines the <see cref="Target"/> property
/// </summary>
public static readonly DirectProperty<FlyoutBase, Control?> TargetProperty =
AvaloniaProperty.RegisterDirect<FlyoutBase, Control?>(nameof(Target), x => x.Target);
/// <summary>
/// Defines the <see cref="Placement"/> property
/// </summary>
public static readonly StyledProperty<FlyoutPlacementMode> PlacementProperty =
AvaloniaProperty.Register<FlyoutBase, FlyoutPlacementMode>(nameof(Placement));
/// <summary>
/// Defines the <see cref="ShowMode"/> property
/// </summary>
public static readonly DirectProperty<FlyoutBase, FlyoutShowMode> ShowModeProperty =
AvaloniaProperty.RegisterDirect<FlyoutBase, FlyoutShowMode>(nameof(ShowMode),
x => x.ShowMode, (x, v) => x.ShowMode = v);
/// <summary>
/// Defines the AttachedFlyout property
/// </summary>
public static readonly AttachedProperty<FlyoutBase?> AttachedFlyoutProperty =
AvaloniaProperty.RegisterAttached<FlyoutBase, Control, FlyoutBase?>("AttachedFlyout", null);
@ -39,24 +54,36 @@ namespace Avalonia.Controls.Primitives
Rect? enlargedPopupRect;
IDisposable? transientDisposable;
/// <summary>
/// Gets whether this Flyout is currently Open
/// </summary>
public bool IsOpen
{
get => _isOpen;
private set => SetAndRaise(IsOpenProperty, ref _isOpen, value);
}
/// <summary>
/// Gets or sets the desired placement
/// </summary>
public FlyoutPlacementMode Placement
{
get => GetValue(PlacementProperty);
set => SetValue(PlacementProperty, value);
}
/// <summary>
/// Gets or sets the desired ShowMode
/// </summary>
public FlyoutShowMode ShowMode
{
get => _showMode;
set => SetAndRaise(ShowModeProperty, ref _showMode, value);
}
/// <summary>
/// Gets the Target used for showing the Flyout
/// </summary>
public Control? Target
{
get => _target;
@ -84,16 +111,29 @@ namespace Avalonia.Controls.Primitives
flyout?.ShowAt(flyoutOwner);
}
/// <summary>
/// Shows the Flyout at the given Control
/// </summary>
/// <param name="placementTarget">The control to show the Flyout at</param>
public void ShowAt(Control placementTarget)
{
ShowAtCore(placementTarget);
}
/// <summary>
/// Shows the Flyout for the given control at the current pointer location, as in a ContextFlyout
/// </summary>
/// <param name="placementTarget">The target control</param>
/// <param name="showAtPointer">True to show at pointer</param>
public void ShowAt(Control placementTarget, bool showAtPointer)
{
ShowAtCore(placementTarget, showAtPointer);
}
/// <summary>
/// Hides the Flyout
/// </summary>
/// <param name="canCancel">Whether or not this closing action can be cancelled</param>
public void Hide(bool canCancel = true)
{
if (!IsOpen)
@ -253,6 +293,10 @@ namespace Avalonia.Controls.Primitives
Closed?.Invoke(this, null);
}
/// <summary>
/// Used to create the content the Flyout displays
/// </summary>
/// <returns></returns>
protected abstract Control CreatePresenter();
private void InitPopup()
@ -416,8 +460,7 @@ namespace Avalonia.Controls.Primitives
c.ContextFlyout.ShowAt(c, true);
}
}
}
}
}
}
}

6
src/Avalonia.Controls/Flyouts/FlyoutPlacementMode.cs

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Avalonia.Controls
namespace Avalonia.Controls
{
public enum FlyoutPlacementMode
{

6
src/Avalonia.Controls/Flyouts/FlyoutPresenter.cs

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Avalonia.Controls
namespace Avalonia.Controls
{
public class FlyoutPresenter : ContentControl
{

15
src/Avalonia.Controls/Flyouts/MenuFlyout.cs

@ -1,11 +1,8 @@
using System.Collections;
using System.Collections.Specialized;
using Avalonia.Collections;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Input;
using Avalonia.Metadata;
using Avalonia.Styling;
#nullable enable
@ -18,16 +15,25 @@ namespace Avalonia.Controls
_items = new AvaloniaList<object>();
}
/// <summary>
/// Defines the <see cref="Items"/> property
/// </summary>
public static readonly DirectProperty<MenuFlyout, IEnumerable> ItemsProperty =
ItemsControl.ItemsProperty.AddOwner<MenuFlyout>(x => x.Items,
(x, v) => x.Items = v);
/// <summary>
/// Defines the <see cref="ItemTemplate"/> property
/// </summary>
public static readonly DirectProperty<MenuFlyout, IDataTemplate?> ItemTemplateProperty =
AvaloniaProperty.RegisterDirect<MenuFlyout, IDataTemplate?>(nameof(ItemTemplate),
x => x.ItemTemplate, (x, v) => x.ItemTemplate = v);
public Classes? FlyoutPresenterClasses => _classes ??= new Classes();
/// <summary>
/// Gets or sets the items of the MenuFlyout
/// </summary>
[Content]
public IEnumerable Items
{
@ -35,6 +41,9 @@ namespace Avalonia.Controls
set => SetAndRaise(ItemsProperty, ref _items, value);
}
/// <summary>
/// Gets or sets the template used for the items
/// </summary>
public IDataTemplate? ItemTemplate
{
get => _itemTemplate;

Loading…
Cancel
Save