-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create AttachedToLogicalTreeBehavior.cs
- Loading branch information
1 parent
e4f7cab
commit 23ae860
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Avalonia.Xaml.Interactions.Custom/AttachedToLogicalTreeBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |