Skip to content

Incorrect target type for RelativeAncestor attached properties #106

@Sergio0694

Description

@Sergio0694

Describe the bug

The attached properties for the "relative ancestor" feature are currently targeting the wrong type:

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/44ad0cc6806c99f1a693c923cb94ea7551718c13/Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.RelativeAncestor.cs#L18-L21

These are defined in FrameworkElementExtensions but target a DependencyObject. This is not correct on its own, but in particular it also makes the APIs technically more error prone, as there is no type guarantee at build-time, and we're doing additional checks at runtime to ensure the input elements are in fact FrameworkElement-s, otherwise we do nothing:

https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/44ad0cc6806c99f1a693c923cb94ea7551718c13/Microsoft.Toolkit.Uwp.UI/Extensions/FrameworkElement/FrameworkElementExtensions.RelativeAncestor.cs#L62-L65

Given that these APIs only make sense for FrameworkElement instances, and that they're defined within FrameworkElementExtensions too, we should update the signature and have them only target FrameworkElement objects. I should note: this would not be a source breaking change when the API was being used correctly, but it would be a binary breaking change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions