ControlHierarchyCreator.cs 945 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections.Generic;
  2. using Avalonia.Controls;
  3. namespace Avalonia.Benchmarks
  4. {
  5. internal class ControlHierarchyCreator
  6. {
  7. public static List<Control> CreateChildren(List<Control> controls, Panel parent, int childCount, int innerCount, int iterations)
  8. {
  9. for (var i = 0; i < childCount; ++i)
  10. {
  11. var control = new StackPanel();
  12. parent.Children.Add(control);
  13. for (int j = 0; j < innerCount; ++j)
  14. {
  15. var child = new Button();
  16. parent.Children.Add(child);
  17. controls.Add(child);
  18. }
  19. if (iterations > 0)
  20. {
  21. CreateChildren(controls, control, childCount, innerCount, iterations - 1);
  22. }
  23. controls.Add(control);
  24. }
  25. return controls;
  26. }
  27. }
  28. }