TestTemplatedRoot.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Avalonia.Controls;
  5. using Avalonia.Controls.Presenters;
  6. using Avalonia.Controls.Templates;
  7. using Avalonia.Layout;
  8. using Avalonia.Platform;
  9. using Avalonia.Rendering;
  10. using Avalonia.Styling;
  11. namespace Avalonia.UnitTests
  12. {
  13. public class TestTemplatedRoot : ContentControl, ILayoutRoot, INameScope, IRenderRoot, IStyleRoot
  14. {
  15. private readonly NameScope _nameScope = new NameScope();
  16. public TestTemplatedRoot()
  17. {
  18. Template = new FuncControlTemplate<TestTemplatedRoot>(x => new ContentPresenter
  19. {
  20. Name = "PART_ContentPresenter",
  21. });
  22. }
  23. public event EventHandler<NameScopeEventArgs> Registered
  24. {
  25. add { _nameScope.Registered += value; }
  26. remove { _nameScope.Registered -= value; }
  27. }
  28. public event EventHandler<NameScopeEventArgs> Unregistered
  29. {
  30. add { _nameScope.Unregistered += value; }
  31. remove { _nameScope.Unregistered -= value; }
  32. }
  33. public Size ClientSize => new Size(100, 100);
  34. public Size MaxClientSize => Size.Infinity;
  35. public double LayoutScaling => 1;
  36. public ILayoutManager LayoutManager { get; set; } = new LayoutManager();
  37. public double RenderScaling => 1;
  38. public IRenderTarget RenderTarget => null;
  39. public IRenderer Renderer => null;
  40. public IRenderTarget CreateRenderTarget()
  41. {
  42. throw new NotImplementedException();
  43. }
  44. public void Invalidate(Rect rect)
  45. {
  46. throw new NotImplementedException();
  47. }
  48. public Point PointToClient(PixelPoint p) => p.ToPoint(1);
  49. public PixelPoint PointToScreen(Point p) => PixelPoint.FromPoint(p, 1);
  50. void INameScope.Register(string name, object element)
  51. {
  52. _nameScope.Register(name, element);
  53. }
  54. object INameScope.Find(string name)
  55. {
  56. return _nameScope.Find(name);
  57. }
  58. void INameScope.Unregister(string name)
  59. {
  60. _nameScope.Unregister(name);
  61. }
  62. }
  63. }