Xamarincommunitytoolkit: [Enhancement | Discussion] Look into using XmlnsDefinition

Created on 30 Sep 2020  路  5Comments  路  Source: xamarin/XamarinCommunityToolkit

@dansiegel proposed to use XmlnsDefinition to make it easier to consume this library. Thoughts? Pros? Cons?

feature-request needs-more-discussion

Most helpful comment

@pictos keep in mind that there is lots of code on StackOverflow showing use of Xamarin.Forms.Maps without a unique namespace alias. If someone sees it's not there I think a quick search or SO comment would solve any questions.

Personally for the toolkit I think a low barrier to entry is highly desirable. Something that is just install a NuGet and then use whatever you need would help make the toolkit really feel like an official community toolkit. Just my two cents.

All 5 comments

Adding the XmlnsDefinitionAttribute to the assembly really is super easy as all we're talking about is adding this to the shared AssemblyInfo

[assembly: XmlnsDefinition("http://somedomain.com", "Xamarin.CommunityToolkit.Converters")]
[assembly: XmlnsDefinition("http://somedomain.com", "Xamarin.CommunityToolkit.UI.Views")]

Probably more thought should go into what that namespace should be. For virtually every Xamarin.Forms library out there I would suggest they have their own unique namespace... so you might have:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:toolkit="http:/somedomain.com">
  <toolkit:CameraView />

Given the more official state of the Community Toolkit, some consideration should actually be given to whether or not that definition should use the default Xamarin.Forms namespace so that the toolkit just feels like a natural extension of Xamarin.Forms similar to how you would install Xamarin.Forms.Maps as an additional nuget package but you don't need to do anything special to consume it in your XAML.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms">
  <CameraView />

Keep in mind that whatever url you pick has no requirement of being a valid url... for instance the default xml namespace for Xamarin.Forms gets caught by the global xamarin.com redirect for unknown resources, and the url for xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" simply returns a 404

Thanks for explaining this @dansiegel this is something I was not aware of. While I personally like the idea of having separate namespaces for Xamarin.Forms vs the Toolkit I think it would make sense to include in the standard Xamarin.Forms namespace as you suggested.

Making it a natural extension of Xamarin.Forms will make this toolkit easier for developers to start using and create a low barrier to entry.

I really like the idea to have the same namespace for both XF and XCT... But this can be trickier for devs that aren't aware of XCT, imagine that situation, that dev copy code from the internet and that code is something like:

<StackLayout>
   <CameraView/>
</StackLayout>

If the dev doesn't have the XCT installed the project will fail without a good error message. Now, having something like:

<StackLayout>
   <xct: CameraView/>
</StackLayout>

That xct prefix indicates that the devs need something else to make that code works.

@pictos keep in mind that there is lots of code on StackOverflow showing use of Xamarin.Forms.Maps without a unique namespace alias. If someone sees it's not there I think a quick search or SO comment would solve any questions.

Personally for the toolkit I think a low barrier to entry is highly desirable. Something that is just install a NuGet and then use whatever you need would help make the toolkit really feel like an official community toolkit. Just my two cents.

keep in mind that there is lots of code on StackOverflow showing use of Xamarin.Forms.Maps without a unique namespace alias.

You have a (good) point

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jfversluis picture jfversluis  路  6Comments

jsmarcus picture jsmarcus  路  5Comments

SunnyMukherjee picture SunnyMukherjee  路  3Comments

roubachof picture roubachof  路  4Comments

varyamereon picture varyamereon  路  4Comments