InitializationOrderTracker.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }
  28. void ISupportInitialize.EndInit()
  29. {
  30. --InitState;
  31. base.EndInit();
  32. }
  33. }
  34. }