DecoratedWindow.xaml.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Markup.Xaml;
  4. using System;
  5. using Avalonia.Input;
  6. namespace ControlCatalog
  7. {
  8. public class DecoratedWindow : Window
  9. {
  10. public DecoratedWindow()
  11. {
  12. this.InitializeComponent();
  13. }
  14. void SetupSide(string name, StandardCursorType cursor, WindowEdge edge)
  15. {
  16. var ctl = this.Get<Control>(name);
  17. ctl.Cursor = new Cursor(cursor);
  18. ctl.PointerPressed += (i, e) =>
  19. {
  20. BeginResizeDrag(edge, e);
  21. };
  22. }
  23. private void InitializeComponent()
  24. {
  25. AvaloniaXamlLoader.Load(this);
  26. this.Get<Control>("TitleBar").PointerPressed += (i, e) =>
  27. {
  28. BeginMoveDrag(e);
  29. };
  30. SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West);
  31. SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East);
  32. SetupSide("Top", StandardCursorType.TopSide, WindowEdge.North);
  33. SetupSide("Bottom", StandardCursorType.BottomSide, WindowEdge.South);
  34. SetupSide("TopLeft", StandardCursorType.TopLeftCorner, WindowEdge.NorthWest);
  35. SetupSide("TopRight", StandardCursorType.TopRightCorner, WindowEdge.NorthEast);
  36. SetupSide("BottomLeft", StandardCursorType.BottomLeftCorner, WindowEdge.SouthWest);
  37. SetupSide("BottomRight", StandardCursorType.BottomRightCorner, WindowEdge.SouthEast);
  38. this.Get<Button>("MinimizeButton").Click += delegate { this.WindowState = WindowState.Minimized; };
  39. this.Get<Button>("MaximizeButton").Click += delegate
  40. {
  41. WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  42. };
  43. this.Get<Button>("CloseButton").Click += delegate
  44. {
  45. Close();
  46. };
  47. }
  48. }
  49. }