Xamarin.forms: Expose XmlnsDefinitionAttribute and XmlnsPrefixAttribute

Created on 30 Jun 2018  路  6Comments  路  Source: xamarin/Xamarin.Forms

Description

Please consider exposing XmlnsDefinitionAttribute and XmlnsPrefixAttribute, so we can register a simple-to-use namespace for all our controls, rather than having to rely on namespace + assemblyname. This allows us to us the same prefix for a range of assemblies and namespaces, without having to register a gazillion prefixes.

ie

<ContentPage
   xmlns:CompanyName="http://schemas.companyname.com/winfx/2018">

 <CompanyName:SomeControl />

</ContentPage>

This class is already there but internal:
https://github.com/xamarin/Xamarin.Forms/blob/e6d5186c8acbf37b877c7ca3c77a378352a3743d/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs#L9

And there's a comment in the code already saying this should be a future extensibility point:
https://github.com/xamarin/Xamarin.Forms/blob/4d9a5bf3706778770026a18ae81a7dd5c4c15db4/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs#L17

Stuff like this makes it really easy for component vendors to spread their controls over multiple assemblies, and/or namespaces, while keeping the same xmlns prefix for all their controls.

Subnote: This is also a highly voted feature for UWP as well: https://wpdev.uservoice.com/forums/110705-universal-windows-platform/suggestions/9523650-add-support-for-xmlnsdefinitionattribute

Most helpful comment

We would love this attribute as well.

All 6 comments

@peter0302 Awesome, but that's only half of it. It's missing XmlnsPrefixAttribute which helps designers and intellisense define a good consistent prefix across all pages.

Oh I glossed over that part.
I'm not familiar with how XmlnsPrefixAttribute is used in practice can you explain?

just a thought here... but I'm not sure that these attributes need to be exposed, but rather that the tooling should be updated around forms to simply look for attributes with these names the same as with the Linker attributes. It seems like a much bigger win if I can write a cross platform library have my own attribute with these names, and XF, UWP, and WPF automatically recognized my attributes and treated them the same as their attributes... I realize the full scope of that goes beyond XF, but just a thought.

If you look at the PR there's actually a lot more that had to be done than just exposing the attribute. XF is (currently) looking for it only in certain hard coded assemblies, and certain components weren't looking for it at all. But as least as far as XmlnsDefinitionAttribute that's exposed and fully functional in my PR. I'm sure the team will get to reviewing it when they have time.

We would love this attribute as well.

Was this page helpful?
0 / 5 - 0 ratings