ToolTipPage.xaml.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using Avalonia;
  3. using Avalonia.Controls;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Controls.Primitives.PopupPositioning;
  6. using Avalonia.Markup.Xaml;
  7. namespace ControlCatalog.Pages
  8. {
  9. public class ToolTipPage : UserControl
  10. {
  11. public ToolTipPage()
  12. {
  13. this.InitializeComponent();
  14. }
  15. private void InitializeComponent()
  16. {
  17. AvaloniaXamlLoader.Load(this);
  18. }
  19. private void ToolTipOpening(object? sender, CancelRoutedEventArgs args)
  20. {
  21. ((Control)args.Source!).SetValue(ToolTip.TipProperty, "New tip set from ToolTipOpening.");
  22. }
  23. public void CustomPlacementCallback(CustomPopupPlacement placement)
  24. {
  25. var r = new Random().Next();
  26. placement.Anchor = (r % 4) switch
  27. {
  28. 1 => PopupAnchor.Top,
  29. 2 => PopupAnchor.Left,
  30. 3 => PopupAnchor.Right,
  31. _ => PopupAnchor.Bottom,
  32. };
  33. placement.Gravity = (r % 4) switch
  34. {
  35. 1 => PopupGravity.Top,
  36. 2 => PopupGravity.Left,
  37. 3 => PopupGravity.Right,
  38. _ => PopupGravity.Bottom,
  39. };
  40. placement.Offset = new Point(r % 20, r % 20);
  41. }
  42. }
  43. }