TestTemplatedRoot.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 ILayoutManager LayoutManager => AvaloniaLocator.Current.GetService<ILayoutManager>();
  34. public IRenderTarget RenderTarget => null;
  35. public IRenderer Renderer => null;
  36. public IRenderTarget CreateRenderTarget()
  37. {
  38. throw new NotImplementedException();
  39. }
  40. public void Invalidate(Rect rect)
  41. {
  42. throw new NotImplementedException();
  43. }
  44. public Point PointToClient(Point p) => p;
  45. public Point PointToScreen(Point p) => p;
  46. void INameScope.Register(string name, object element)
  47. {
  48. _nameScope.Register(name, element);
  49. }
  50. object INameScope.Find(string name)
  51. {
  52. return _nameScope.Find(name);
  53. }
  54. void INameScope.Unregister(string name)
  55. {
  56. _nameScope.Unregister(name);
  57. }
  58. }
  59. }