TestTemplatedRoot.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. public event EventHandler<NameScopeEventArgs> Registered
  21. {
  22. add { _nameScope.Registered += value; }
  23. remove { _nameScope.Registered -= value; }
  24. }
  25. public event EventHandler<NameScopeEventArgs> Unregistered
  26. {
  27. add { _nameScope.Unregistered += value; }
  28. remove { _nameScope.Unregistered -= value; }
  29. }
  30. public Size ClientSize => new Size(100, 100);
  31. public Size MaxClientSize => Size.Infinity;
  32. public double LayoutScaling => 1;
  33. public double RenderScaling => 1;
  34. public ILayoutManager LayoutManager => AvaloniaLocator.Current.GetService<ILayoutManager>();
  35. public IRenderTarget RenderTarget => null;
  36. public IRenderer Renderer => null;
  37. public IRenderTarget CreateRenderTarget()
  38. {
  39. throw new NotImplementedException();
  40. }
  41. public void Invalidate(Rect rect)
  42. {
  43. throw new NotImplementedException();
  44. }
  45. public Point PointToClient(Point p) => p;
  46. public Point PointToScreen(Point p) => p;
  47. void INameScope.Register(string name, object element)
  48. {
  49. _nameScope.Register(name, element);
  50. }
  51. object INameScope.Find(string name)
  52. {
  53. return _nameScope.Find(name);
  54. }
  55. void INameScope.Unregister(string name)
  56. {
  57. _nameScope.Unregister(name);
  58. }
  59. }
  60. }