Skip to content

Commit 87cdaa1

Browse files
committed
Refactor base interface
1 parent b5c4206 commit 87cdaa1

File tree

5 files changed

+63
-42
lines changed

5 files changed

+63
-42
lines changed

src/Avalonia.Xaml.Interactivity/Behavior.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Avalonia.Xaml.Interactivity;
88
/// <summary>
99
/// A base class for behaviors, implementing the basic plumbing of <see cref="IBehavior"/>.
1010
/// </summary>
11-
public abstract class Behavior : AvaloniaObject, IBehavior, IInternalBehavior
11+
public abstract class Behavior : AvaloniaObject, IBehavior, IBehaviorEventsHandler
1212
{
1313
/// <summary>
1414
/// Identifies the <seealso cref="IsEnabled"/> avalonia property.
@@ -85,17 +85,17 @@ protected virtual void OnDetaching()
8585
{
8686
}
8787

88-
void IInternalBehavior.AttachedToVisualTreeImpl() => OnAttachedToVisualTree();
88+
void IBehaviorEventsHandler.AttachedToVisualTreeEventHandler() => OnAttachedToVisualTree();
8989

90-
void IInternalBehavior.DetachedFromVisualTreeImpl() => OnDetachedFromVisualTree();
90+
void IBehaviorEventsHandler.DetachedFromVisualTreeEventHandler() => OnDetachedFromVisualTree();
9191

92-
void IInternalBehavior.AttachedToLogicalTreeImpl() => OnAttachedToLogicalTree();
92+
void IBehaviorEventsHandler.AttachedToLogicalTreeEventHandler() => OnAttachedToLogicalTree();
9393

94-
void IInternalBehavior.DetachedFromLogicalTreeImpl() => OnDetachedFromLogicalTree();
94+
void IBehaviorEventsHandler.DetachedFromLogicalTreeEventHandler() => OnDetachedFromLogicalTree();
9595

96-
void IInternalBehavior.LoadedImpl() => OnLoaded();
96+
void IBehaviorEventsHandler.LoadedEventHandler() => OnLoaded();
9797

98-
void IInternalBehavior.UnloadedImpl() => OnUnloaded();
98+
void IBehaviorEventsHandler.UnloadedEventHandler() => OnUnloaded();
9999

100100
/// <summary>
101101
/// Called after the <see cref="AssociatedObject"/> is attached to the visual tree.

src/Avalonia.Xaml.Interactivity/BehaviorCollection.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ internal void AttachedToVisualTree()
8181
{
8282
foreach (var item in this)
8383
{
84-
if (item is IInternalBehavior behavior)
84+
if (item is IBehaviorEventsHandler behaviorEventsHandler)
8585
{
86-
behavior.AttachedToVisualTreeImpl();
86+
behaviorEventsHandler.AttachedToVisualTreeEventHandler();
8787
}
8888
}
8989
}
@@ -92,9 +92,9 @@ internal void DetachedFromVisualTree()
9292
{
9393
foreach (var item in this)
9494
{
95-
if (item is IInternalBehavior behavior and IBehavior { AssociatedObject: not null})
95+
if (item is IBehaviorEventsHandler behaviorEventsHandler and IBehavior { AssociatedObject: not null})
9696
{
97-
behavior.DetachedFromVisualTreeImpl();
97+
behaviorEventsHandler.DetachedFromVisualTreeEventHandler();
9898
}
9999
}
100100
}
@@ -103,9 +103,9 @@ internal void AttachedToLogicalTree()
103103
{
104104
foreach (var item in this)
105105
{
106-
if (item is IInternalBehavior behavior)
106+
if (item is IBehaviorEventsHandler behaviorEventsHandler)
107107
{
108-
behavior.AttachedToLogicalTreeImpl();
108+
behaviorEventsHandler.AttachedToLogicalTreeEventHandler();
109109
}
110110
}
111111
}
@@ -114,9 +114,9 @@ internal void DetachedFromLogicalTree()
114114
{
115115
foreach (var item in this)
116116
{
117-
if (item is IInternalBehavior behavior and IBehavior { AssociatedObject: not null})
117+
if (item is IBehaviorEventsHandler behaviorEventsHandler and IBehavior { AssociatedObject: not null})
118118
{
119-
behavior.DetachedFromLogicalTreeImpl();
119+
behaviorEventsHandler.DetachedFromLogicalTreeEventHandler();
120120
}
121121
}
122122
}
@@ -125,9 +125,9 @@ internal void Loaded()
125125
{
126126
foreach (var item in this)
127127
{
128-
if (item is IInternalBehavior behavior)
128+
if (item is IBehaviorEventsHandler behaviorEventsHandler)
129129
{
130-
behavior.LoadedImpl();
130+
behaviorEventsHandler.LoadedEventHandler();
131131
}
132132
}
133133
}
@@ -136,9 +136,9 @@ internal void Unloaded()
136136
{
137137
foreach (var item in this)
138138
{
139-
if (item is IInternalBehavior behavior and IBehavior { AssociatedObject: not null})
139+
if (item is IBehaviorEventsHandler behaviorEventsHandler and IBehavior { AssociatedObject: not null})
140140
{
141-
behavior.UnloadedImpl();
141+
behaviorEventsHandler.UnloadedEventHandler();
142142
}
143143
}
144144
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace Avalonia.Xaml.Interactivity;
2+
3+
/// <summary>
4+
/// Interface implemented by base behaviors.
5+
/// </summary>
6+
public interface IBehaviorEventsHandler
7+
{
8+
/// <summary>
9+
/// Called when element is attached to the visual tree.
10+
/// </summary>
11+
void AttachedToVisualTreeEventHandler();
12+
13+
/// <summary>
14+
/// Called when element is detached from the visual tree.
15+
/// </summary>
16+
void DetachedFromVisualTreeEventHandler();
17+
18+
/// <summary>
19+
/// Called when element is attached to the logical tree.
20+
/// </summary>
21+
void AttachedToLogicalTreeEventHandler();
22+
23+
/// <summary>
24+
/// Called when element is detached from the logical tree.
25+
/// </summary>
26+
void DetachedFromLogicalTreeEventHandler();
27+
28+
/// <summary>
29+
/// Called when element is loaded.
30+
/// </summary>
31+
void LoadedEventHandler();
32+
33+
/// <summary>
34+
/// Called when element is unloaded.
35+
/// </summary>
36+
void UnloadedEventHandler();
37+
}

src/Avalonia.Xaml.Interactivity/IInternalBehavior.cs

-16
This file was deleted.

src/Avalonia.Xaml.Interactivity/StyledElementBehavior.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Avalonia.Xaml.Interactivity;
99
/// <summary>
1010
/// A base class for behaviors, implementing the basic plumbing of <see cref="IBehavior"/>.
1111
/// </summary>
12-
public abstract class StyledElementBehavior : StyledElement, IBehavior, IInternalBehavior
12+
public abstract class StyledElementBehavior : StyledElement, IBehavior, IBehaviorEventsHandler
1313
{
1414
private IDisposable? _dataContextDisposable;
1515

@@ -95,25 +95,25 @@ protected virtual void OnDetaching()
9595
{
9696
}
9797

98-
void IInternalBehavior.AttachedToVisualTreeImpl() => OnAttachedToVisualTree();
98+
void IBehaviorEventsHandler.AttachedToVisualTreeEventHandler() => OnAttachedToVisualTree();
9999

100-
void IInternalBehavior.DetachedFromVisualTreeImpl() => OnDetachedFromVisualTree();
100+
void IBehaviorEventsHandler.DetachedFromVisualTreeEventHandler() => OnDetachedFromVisualTree();
101101

102-
void IInternalBehavior.AttachedToLogicalTreeImpl()
102+
void IBehaviorEventsHandler.AttachedToLogicalTreeEventHandler()
103103
{
104104
AttachToLogicalTree();
105105
OnAttachedToLogicalTree();
106106
}
107107

108-
void IInternalBehavior.DetachedFromLogicalTreeImpl()
108+
void IBehaviorEventsHandler.DetachedFromLogicalTreeEventHandler()
109109
{
110110
DetachFromLogicalTree();
111111
OnDetachedFromLogicalTree();
112112
}
113113

114-
void IInternalBehavior.LoadedImpl() => OnLoaded();
114+
void IBehaviorEventsHandler.LoadedEventHandler() => OnLoaded();
115115

116-
void IInternalBehavior.UnloadedImpl() => OnUnloaded();
116+
void IBehaviorEventsHandler.UnloadedEventHandler() => OnUnloaded();
117117

118118
/// <summary>
119119
/// Called after the <see cref="AssociatedObject"/> is attached to the visual tree.

0 commit comments

Comments
 (0)