AttachedToLogicalTreeBehavior.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. using System.Reactive.Disposables;
  2. using Avalonia.Xaml.Interactivity;
  3. namespace Avalonia.Xaml.Interactions.Custom;
  4. /// <summary>
  5. /// A base class for behaviors using attached to logical tree event.
  6. /// </summary>
  7. /// <typeparam name="T"></typeparam>
  8. public abstract class AttachedToLogicalTreeBehavior<T> : DisposingBehavior<T> where T : StyledElement
  9. {
  10. private CompositeDisposable? _disposables;
  11. /// <inheritdoc />
  12. protected override void OnAttached(CompositeDisposable disposables)
  13. {
  14. _disposables = disposables;
  15. }
  16. /// <inheritdoc />
  17. protected override void OnAttachedToLogicalTree()
  18. {
  19. OnAttachedToLogicalTree(_disposables!);
  20. }
  21. /// <summary>
  22. /// Called after the <see cref="StyledElementBehavior{T}.AssociatedObject"/> is attached to the logical tree.
  23. /// </summary>
  24. /// <param name="disposable">The group of disposable resources that are disposed together</param>
  25. protected abstract void OnAttachedToLogicalTree(CompositeDisposable disposable);
  26. }