using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Primitives.PopupPositioning;
using Avalonia.Interactivity;
namespace ControlCatalog.Pages
{
public partial class FlyoutsPage : UserControl
{
public FlyoutsPage()
{
InitializeComponent();
AttachedFlyoutPanel.DoubleTapped += Afp_DoubleTapped;
SetXamlTexts();
}
private void Afp_DoubleTapped(object? sender, RoutedEventArgs e)
{
if (sender is Panel p)
{
FlyoutBase.ShowAttachedFlyout(p);
}
}
private void SetXamlTexts()
{
var bfxt = ButtonFlyoutXamlText;
bfxt.Text = "";
var mfxt = this.MenuFlyoutXamlText;
mfxt.Text = "";
var afxt = this.AttachedFlyoutXamlText;
afxt.Text = "\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n" +
"\n\n In DoubleTapped handler:\n" +
"FlyoutBase.ShowAttachedFlyout(AttachedFlyoutPanel);";
var sfxt = this.SharedFlyoutXamlText;
sfxt.Text = "Declare a flyout in Resources:\n" +
"\n" +
" \n" +
" \n" +
" \n" +
" \n" +
" \n\n\n" +
"Then attach the flyout where you want it:\n" +
"";
}
public void CustomPlacementCallback(CustomPopupPlacement placement)
{
var r = new Random().Next();
placement.Anchor = (r % 4) switch
{
1 => PopupAnchor.Top,
2 => PopupAnchor.Left,
3 => PopupAnchor.Right,
_ => PopupAnchor.Bottom,
};
placement.Gravity = (r % 4) switch
{
1 => PopupGravity.Top,
2 => PopupGravity.Left,
3 => PopupGravity.Right,
_ => PopupGravity.Bottom,
};
placement.Offset = new Point(r % 20, r % 20);
}
}
}