FlyoutsPage.axaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Primitives;
  3. using Avalonia.Interactivity;
  4. namespace ControlCatalog.Pages
  5. {
  6. public partial class FlyoutsPage : UserControl
  7. {
  8. public FlyoutsPage()
  9. {
  10. InitializeComponent();
  11. var afp = this.FindControl<Panel>("AttachedFlyoutPanel");
  12. if (afp != null)
  13. {
  14. afp.DoubleTapped += Afp_DoubleTapped;
  15. }
  16. SetXamlTexts();
  17. }
  18. private void Afp_DoubleTapped(object? sender, RoutedEventArgs e)
  19. {
  20. if (sender is Panel p)
  21. {
  22. FlyoutBase.ShowAttachedFlyout(p);
  23. }
  24. }
  25. private void SetXamlTexts()
  26. {
  27. var bfxt = this.Get<TextBlock>("ButtonFlyoutXamlText");
  28. bfxt.Text = "<Button Content=\"Click me!\">\n" +
  29. " <Button.Flyout>\n" +
  30. " <Flyout>\n" +
  31. " <Panel Width=\"100\" Height=\"100\">\n" +
  32. " <TextBlock Text=\"Flyout Content!\" />\n" +
  33. " </Panel>\n" +
  34. " </Flyout>\n" +
  35. " </Button.Flyout>\n</Button>";
  36. var mfxt = this.Get<TextBlock>("MenuFlyoutXamlText");
  37. mfxt.Text = "<Button Content=\"Click me!\">\n" +
  38. " <Button.Flyout>\n" +
  39. " <MenuFlyout>\n" +
  40. " <MenuItem Header=\"Item 1\">\n" +
  41. " <MenuItem Header=\"Item 2\">\n" +
  42. " </MenuFlyout>\n" +
  43. " </Button.Flyout>\n</Button>";
  44. var afxt = this.Get<TextBlock>("AttachedFlyoutXamlText");
  45. afxt.Text = "<Panel Name=\"AttachedFlyoutPanel\">\n" +
  46. " <FlyoutBase.AttachedFlyout>\n" +
  47. " <Flyout>\n" +
  48. " <Panel Height=\"100\">\n" +
  49. " <TextBlock Text=\"Attached Flyout\" />\n" +
  50. " </Panel>\n" +
  51. " </Flyout>\n" +
  52. " </FlyoutBase.AttachedFlyout>\n</Panel>" +
  53. "\n\n In DoubleTapped handler:\n" +
  54. "FlyoutBase.ShowAttachedFlyout(AttachedFlyoutPanel);";
  55. var sfxt = this.Get<TextBlock>("SharedFlyoutXamlText");
  56. sfxt.Text = "Declare a flyout in Resources:\n" +
  57. "<Window.Resources>\n" +
  58. " <Flyout x:Key=\"SharedFlyout\">\n" +
  59. " <Panel Width=\"100\" Height=\"100\">\n" +
  60. " <TextBlock Text=\"Flyout Content!\" />\n" +
  61. " </Panel>\n" +
  62. " </Flyout>\n</Window.Resources>\n\n" +
  63. "Then attach the flyout where you want it:\n" +
  64. "<Button Content=\"Launch Flyout here\" Flyout=\"{StaticResource SharedFlyout}\" />";
  65. }
  66. }
  67. }