Skip to content

Commit 7a3ed80

Browse files
committed
Experimental interface IBehavior
1 parent f69a6ed commit 7a3ed80

File tree

11 files changed

+84
-14
lines changed

11 files changed

+84
-14
lines changed

src/Controls/src/Core/Interactivity/Behavior.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.Maui.Controls
77
/// Base class for generalized user-defined behaviors that can respond to arbitrary conditions and events.
88
/// </summary>
99
/// <remarks>Application developers should specialize the <see cref="Behavior{T}" /> generic class, instead of directly using <see cref="Behavior" />.</remarks>
10-
public abstract class Behavior : BindableObject, IAttachedObject
10+
public abstract class Behavior : BindableObject, IBehavior
1111
{
1212
/// <summary>
1313
/// Creates a new <see cref="Behavior" /> with default values.
@@ -54,7 +54,7 @@ protected virtual void OnDetachingFrom(BindableObject bindable)
5454

5555
/// <inheritdoc/>
5656
/// <typeparam name="T">The type of object this behavior will be applied to.</typeparam>
57-
public abstract class Behavior<T> : Behavior where T : BindableObject
57+
public abstract class Behavior<T> : Behavior, IBehavior<T> where T : BindableObject
5858
{
5959
/// <inheritdoc/>
6060
protected Behavior() : base(typeof(T))
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
#nullable disable
22
namespace Microsoft.Maui.Controls
33
{
4-
internal interface IAttachedObject
4+
5+
/// <summary>
6+
/// Defines a contract for objects that can be attached to a <see cref="BindableObject"/>.
7+
/// This interface is typically implemented by behaviors or effects that need to interact with
8+
/// the lifecycle or properties of a visual element in the UI.
9+
/// </summary>
10+
public interface IAttachedObject
511
{
12+
13+
/// <summary>
14+
/// Attaches the object to the specified <see cref="BindableObject"/>.
15+
/// This method is called when the object is added to the visual tree.
16+
/// </summary>
17+
/// <param name="bindable">The <see cref="BindableObject"/> to attach to.</param>
618
void AttachTo(BindableObject bindable);
19+
20+
/// <summary>
21+
/// Detaches the object from the specified <see cref="BindableObject"/>.
22+
/// This method is called when the object is removed from the visual tree.
23+
/// </summary>
24+
/// <param name="bindable">The <see cref="BindableObject"/> to detach from.</param>
725
void DetachFrom(BindableObject bindable);
826
}
927
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#nullable disable
2+
using System.ComponentModel;
3+
4+
namespace Microsoft.Maui.Controls
5+
{
6+
7+
/// <summary>
8+
/// Represents a behavior that can be attached to a <see cref="BindableObject"/>.
9+
/// </summary>
10+
public interface IBehavior : INotifyPropertyChanged, IAttachedObject
11+
{
12+
}
13+
14+
/// <summary>
15+
/// Represents a behavior that can be attached to a specific type of <see cref="BindableObject"/>.
16+
/// This generic interface allows behaviors to be strongly typed to the target element.
17+
/// </summary>
18+
/// <typeparam name="T">The type of <see cref="BindableObject"/> the behavior can attach to.</typeparam>
19+
public interface IBehavior<T> : IBehavior where T : BindableObject
20+
{
21+
}
22+
}

src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@
632632
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
633633
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
634634
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
635+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
636+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
637+
~Microsoft.Maui.Controls.IBehavior<T>
635638
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
636639
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
637640
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1816,7 +1819,7 @@
18161819
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
18171820
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
18181821
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1819-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1822+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
18201823
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
18211824
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
18221825
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -5239,6 +5242,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
52395242
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
52405243
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
52415244
Microsoft.Maui.Controls.IAppLinks
5245+
Microsoft.Maui.Controls.IAttachedObject
5246+
Microsoft.Maui.Controls.IBehavior
52425247
Microsoft.Maui.Controls.IBindableLayout
52435248
Microsoft.Maui.Controls.IBorderElement
52445249
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@
665665
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
666666
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
667667
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
668+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
669+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
670+
~Microsoft.Maui.Controls.IBehavior<T>
668671
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
669672
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
670673
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1824,7 +1827,7 @@
18241827
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
18251828
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
18261829
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1827-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1830+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
18281831
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
18291832
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
18301833
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -5435,6 +5438,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
54355438
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
54365439
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
54375440
Microsoft.Maui.Controls.IAppLinks
5441+
Microsoft.Maui.Controls.IAttachedObject
5442+
Microsoft.Maui.Controls.IBehavior
54385443
Microsoft.Maui.Controls.IBindableLayout
54395444
Microsoft.Maui.Controls.IBorderElement
54405445
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@
665665
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
666666
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
667667
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
668+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
669+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
670+
~Microsoft.Maui.Controls.IBehavior<T>
668671
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
669672
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
670673
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1824,7 +1827,7 @@
18241827
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
18251828
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
18261829
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1827-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1830+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
18281831
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
18291832
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
18301833
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -5435,6 +5438,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
54355438
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
54365439
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
54375440
Microsoft.Maui.Controls.IAppLinks
5441+
Microsoft.Maui.Controls.IAttachedObject
5442+
Microsoft.Maui.Controls.IBehavior
54385443
Microsoft.Maui.Controls.IBindableLayout
54395444
Microsoft.Maui.Controls.IBorderElement
54405445
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@
15941594
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
15951595
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
15961596
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1597-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1597+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
15981598
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
15991599
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
16001600
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary

src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@
535535
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
536536
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
537537
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
538+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
539+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
540+
~Microsoft.Maui.Controls.IBehavior<T>
538541
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
539542
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
540543
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1664,7 +1667,7 @@
16641667
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
16651668
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
16661669
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1667-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1670+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
16681671
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
16691672
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
16701673
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -4904,6 +4907,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
49044907
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
49054908
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
49064909
Microsoft.Maui.Controls.IAppLinks
4910+
Microsoft.Maui.Controls.IAttachedObject
4911+
Microsoft.Maui.Controls.IBehavior
49074912
Microsoft.Maui.Controls.IBindableLayout
49084913
Microsoft.Maui.Controls.IBorderElement
49094914
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

src/Controls/src/Core/PublicAPI/net/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@
517517
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
518518
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
519519
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
520+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
521+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
522+
~Microsoft.Maui.Controls.IBehavior<T>
520523
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
521524
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
522525
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1590,7 +1593,7 @@
15901593
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
15911594
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
15921595
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1593-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1596+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
15941597
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
15951598
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
15961599
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -4660,6 +4663,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
46604663
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
46614664
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
46624665
Microsoft.Maui.Controls.IAppLinks
4666+
Microsoft.Maui.Controls.IAttachedObject
4667+
Microsoft.Maui.Controls.IBehavior
46634668
Microsoft.Maui.Controls.IBindableLayout
46644669
Microsoft.Maui.Controls.IBorderElement
46654670
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Shipped.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@
517517
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
518518
~Microsoft.Maui.Controls.IAppLinks.DeregisterLink(System.Uri appLinkUri) -> void
519519
~Microsoft.Maui.Controls.IAppLinks.RegisterLink(Microsoft.Maui.Controls.IAppLinkEntry appLink) -> void
520+
~Microsoft.Maui.Controls.IAttachedObject.AttachTo(Microsoft.Maui.Controls.BindableObject bindable) -> void
521+
~Microsoft.Maui.Controls.IAttachedObject.DetachFrom(Microsoft.Maui.Controls.BindableObject bindable) -> void
522+
~Microsoft.Maui.Controls.IBehavior<T>
520523
~Microsoft.Maui.Controls.IBindableLayout.Children.get -> System.Collections.IList
521524
~Microsoft.Maui.Controls.IBorderElement.Background.get -> Microsoft.Maui.Controls.Brush
522525
~Microsoft.Maui.Controls.IBorderElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
@@ -1590,7 +1593,7 @@
15901593
~Microsoft.Maui.Controls.VisualElement.Background.set -> void
15911594
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.get -> Microsoft.Maui.Graphics.Color
15921595
~Microsoft.Maui.Controls.VisualElement.BackgroundColor.set -> void
1593-
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.Behavior>
1596+
~Microsoft.Maui.Controls.VisualElement.Behaviors.get -> System.Collections.Generic.IList<Microsoft.Maui.Controls.IBehavior>
15941597
~Microsoft.Maui.Controls.VisualElement.Clip.get -> Microsoft.Maui.Controls.Shapes.Geometry
15951598
~Microsoft.Maui.Controls.VisualElement.Clip.set -> void
15961599
~Microsoft.Maui.Controls.VisualElement.Resources.get -> Microsoft.Maui.Controls.ResourceDictionary
@@ -4660,6 +4663,8 @@ Microsoft.Maui.Controls.IAppLinkEntry
46604663
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.get -> bool
46614664
Microsoft.Maui.Controls.IAppLinkEntry.IsLinkActive.set -> void
46624665
Microsoft.Maui.Controls.IAppLinks
4666+
Microsoft.Maui.Controls.IAttachedObject
4667+
Microsoft.Maui.Controls.IBehavior
46634668
Microsoft.Maui.Controls.IBindableLayout
46644669
Microsoft.Maui.Controls.IBorderElement
46654670
Microsoft.Maui.Controls.IBorderElement.BorderWidth.get -> double

0 commit comments

Comments
 (0)