InitializationOrderTracker.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Avalonia.Controls;
  4. using Avalonia.LogicalTree;
  5. using System.Collections.Generic;
  6. namespace Avalonia.Markup.Xaml.UnitTests.Xaml
  7. {
  8. public class InitializationOrderTracker : Control,
  9. ISupportInitialize
  10. {
  11. public IList<string> Order { get; } = new List<string>();
  12. public int InitState { get; private set; }
  13. protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
  14. {
  15. Order.Add("AttachedToLogicalTree");
  16. base.OnAttachedToLogicalTree(e);
  17. }
  18. protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
  19. {
  20. Order.Add($"Property {e.Property.Name} Changed");
  21. base.OnPropertyChanged(e);
  22. }
  23. void ISupportInitialize.BeginInit()
  24. {
  25. ++InitState;
  26. base.BeginInit();
  27. Order.Add($"BeginInit {InitState}");
  28. }
  29. void ISupportInitialize.EndInit()
  30. {
  31. --InitState;
  32. base.EndInit();
  33. Order.Add($"EndInit {InitState}");
  34. }
  35. }
  36. }