Skip to content

Commit

Permalink
Create AttachedToLogicalTreeBehavior.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Sep 1, 2024
1 parent e4f7cab commit 23ae860
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Reactive.Disposables;
using Avalonia.Xaml.Interactivity;

namespace Avalonia.Xaml.Interactions.Custom;

/// <summary>
/// A base class for behaviors using attached to logical tree event.
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class AttachedToLogicalTreeBehavior<T> : DisposingBehavior<T> where T : StyledElement
{
private CompositeDisposable? _disposables;

/// <inheritdoc />
protected override void OnAttached(CompositeDisposable disposables)
{
_disposables = disposables;
}

/// <inheritdoc />
protected override void OnAttachedToLogicalTree()
{
OnAttachedToLogicalTree(_disposables!);
}

/// <summary>
/// Called after the <see cref="Behavior{T}.AssociatedObject"/> is attached to the logical tree.
/// </summary>
/// <param name="disposable">The group of disposable resources that are disposed together</param>
protected abstract void OnAttachedToLogicalTree(CompositeDisposable disposable);
}

0 comments on commit 23ae860

Please sign in to comment.