Skip to content

[Feature] Make T for BehaviorBase<T> constraint to DependencyObject or FrameworkElement #3856

@Rosuavio

Description

@Rosuavio

Describe the problem this feature would solve

BehaviorBase<T> supports a lot of our behaviors but as far as its own API for consumption it feels like I can be refined.
Currently T is constrained to UIElement which is more specific than Behavior<T>'s DependencyObject. So BehaviorBase<T> cannot be associated with any DependencyObject like Behavior making it usable in less scenarios.

On the other hand its behavior from its docs

  1. Whenever initially fails, this method will subscribe to to allow lazy initialization.

Only works with FrameworkElements but T is constrained to UIElement.

While the behavior

  1. Prevent duplicate initialization that can happen (prevent multiple OnAttached calls);

will work regardless of the type it feels like constraining T to UIElement is an awkward middle ground.

Describe the solution

Embrace the usefulness outside of the T is FrameworkElement case and make the class usable in more scenarios.

public abstract class BehaviorBase<T> : Behavior<T>
-        where T : UIElement
+        where T : DependencyObject

or

Embrace the behavior of the T is FrameworkElement case and make the class constrained to scenarios where both 1 and 2 work.

public abstract class BehaviorBase<T> : Behavior<T>
-        where T : UIElement
+        where T : FrameworkElement

Describe alternatives you've considered

Do nothing.

Additional context & Screenshots

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions