Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] Make IProvideParentValues Public #13298

Closed
matthewrdev opened this issue Jan 6, 2021 · 2 comments
Closed

[Enhancement] Make IProvideParentValues Public #13298

matthewrdev opened this issue Jan 6, 2021 · 2 comments

Comments

@matthewrdev
Copy link
Contributor

Summary

Expose the IProvideParentValues interface as a public API to allow use by third-party markup extensions.

The IProvideParentValues interface is useful for custom markup extensions as it allows the extension to inspect the current hierarchy in the visual tree. Currently, when retrieving the current view via IProvideValueTarget.TargetObject, the views Parent is unset, leaving IProvideParentValues as the only way we get a controls parent.

For users of Xamarin.Forms who wish to create custom markup extensions, this means that we are unable to inspect the parent hierarchy for a control. This has been flagged previously by the community in #5052.

API Changes

Change IProvideParentValues accessibility from internal to public.

Intended Use Case

When working with Grids in XAML, we specify the location of a control using the Grid.Row/Grid.Column syntax.

<Grid RowDefinitions="*">
  <Label Grid.Row="0" />
</Grid>

By opening up IProvideParentValues as a public interface, we can build markup extensions that allow locations and spans to be specified by name:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition x:Name="labelRow" Height="Auto"/>
  </Grid.RowDefinitions>
  <Label Grid.Row="{local:GridLocation labelRow}" />
</Grid>

To enable this syntax, the GridLocation and GridSpan must be able to find the parent grid for the IProvideValueTarget.TargetObject. Currently these extensions must use reflection to access this API as there is no obvious alternative.

For a full working prototype of these extensions, and a deeper explanation into their potential benefits, please see:

@samhouts samhouts added this to New in Triage Jan 6, 2021
@hartez hartez added this to Under consideration in Enhancements via automation Jan 6, 2021
@hartez hartez removed this from New in Triage Jan 6, 2021
@matthewrdev
Copy link
Contributor Author

As a follow up on this request, I've tested my extensions in both compiled and interpreted XAML and there is no difference in behaviour for the IProvideParentValues interface. In both compiled and interpreted XAML the interface behaves the same and returns the same data.

@jfversluis
Copy link
Member

Thanks for this suggestion! As Xamarin.Forms is now in maintenance mode, this will not happen anymore for Xamarin.Forms. We're only adding bugfixes and stability fixes.

If this is still important to you, make sure to check the .NET MAUI repo and see if it's already on the roadmap. If not, feel free to open a discussion to discuss a change first or open an issue with a detailed feature request. Thanks!

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2022
Enhancements automation moved this from Under consideration to Closed Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Enhancements
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants