DecoratedWindow.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. this.AttachDevTools();
  14. }
  15. void SetupSide(string name, StandardCursorType cursor, WindowEdge edge)
  16. {
  17. var ctl = this.FindControl<Control>(name);
  18. ctl.Cursor = new Cursor(cursor);
  19. ctl.PointerPressed += delegate
  20. {
  21. PlatformImpl?.BeginResizeDrag(edge);
  22. };
  23. }
  24. private void InitializeComponent()
  25. {
  26. AvaloniaXamlLoader.Load(this);
  27. this.FindControl<Control>("TitleBar").PointerPressed += delegate
  28. {
  29. PlatformImpl?.BeginMoveDrag();
  30. };
  31. SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West);
  32. SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East);
  33. SetupSide("Top", StandardCursorType.TopSide, WindowEdge.North);
  34. SetupSide("Bottom", StandardCursorType.BottomSize, WindowEdge.South);
  35. SetupSide("TopLeft", StandardCursorType.TopLeftCorner, WindowEdge.NorthWest);
  36. SetupSide("TopRight", StandardCursorType.TopRightCorner, WindowEdge.NorthEast);
  37. SetupSide("BottomLeft", StandardCursorType.BottomLeftCorner, WindowEdge.SouthWest);
  38. SetupSide("BottomRight", StandardCursorType.BottomRightCorner, WindowEdge.SouthEast);
  39. this.FindControl<Button>("MinimizeButton").Click += delegate { this.WindowState = WindowState.Minimized; };
  40. this.FindControl<Button>("MaximizeButton").Click += delegate
  41. {
  42. WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  43. };
  44. this.FindControl<Button>("CloseButton").Click += delegate
  45. {
  46. Close();
  47. };
  48. }
  49. }
  50. }