FlyoutsPage.axaml.cs 3.1 KB

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