CustomDrawing.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using Avalonia.Controls;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Markup.Xaml;
  5. namespace ControlCatalog.Pages
  6. {
  7. public partial class CustomDrawing : UserControl
  8. {
  9. public CustomDrawing()
  10. {
  11. InitializeComponent();
  12. }
  13. private CustomDrawingExampleControl? _customControl;
  14. public CustomDrawingExampleControl CustomDrawingControl
  15. {
  16. get
  17. {
  18. if (_customControl is not null)
  19. return _customControl;
  20. throw new System.Exception("Control did not get initialized");
  21. }
  22. }
  23. private void InitializeComponent()
  24. {
  25. AvaloniaXamlLoader.Load(this);
  26. var cntrl = this.FindControl<CustomDrawingExampleControl>("CustomDrawingControl");
  27. if (cntrl != null)
  28. {
  29. _customControl = cntrl;
  30. }
  31. else
  32. {
  33. // be sad about it
  34. }
  35. }
  36. private void RotateMinus (object? sender, RoutedEventArgs e)
  37. {
  38. if (_customControl is null) return;
  39. _customControl.Rotation -= Math.PI / 20.0d;
  40. }
  41. private void RotatePlus(object? sender, RoutedEventArgs e)
  42. {
  43. if (_customControl is null)
  44. return;
  45. _customControl.Rotation += Math.PI / 20.0d;
  46. }
  47. private void ZoomIn(object? sender, RoutedEventArgs e)
  48. {
  49. if (_customControl is null)
  50. return;
  51. _customControl.Scale *= 1.2d;
  52. }
  53. private void ZoomOut(object? sender, RoutedEventArgs e)
  54. {
  55. if (_customControl is null)
  56. return;
  57. _customControl.Scale /= 1.2d;
  58. }
  59. }
  60. }