1
0

PointerPage.axaml.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Input;
  4. namespace IntegrationTestApp.Pages;
  5. public partial class PointerPage : UserControl
  6. {
  7. public PointerPage()
  8. {
  9. InitializeComponent();
  10. }
  11. private void PointerPageShowDialog_PointerPressed(object? sender, PointerPressedEventArgs e)
  12. {
  13. void CaptureLost(object? sender, PointerCaptureLostEventArgs e)
  14. {
  15. PointerCaptureStatus.Text = "None";
  16. ((Control)sender!).PointerCaptureLost -= CaptureLost;
  17. }
  18. var window = TopLevel.GetTopLevel(this) as Window ??
  19. throw new AvaloniaInternalException("PointerPage is not attached to a Window.");
  20. var captured = e.Pointer.Captured as Control;
  21. if (captured is not null)
  22. {
  23. captured.PointerCaptureLost += CaptureLost;
  24. }
  25. PointerCaptureStatus.Text = captured?.ToString() ?? "None";
  26. var dialog = new Window
  27. {
  28. Width = 200,
  29. Height = 200,
  30. };
  31. dialog.Content = new Button
  32. {
  33. Content = "Close",
  34. Command = new DelegateCommand(() => dialog.Close()),
  35. };
  36. dialog.ShowDialog(window);
  37. }
  38. }