Question

I want to use a custom ContentPage for my pages in Xamarin.Forms. I tried creating a custom class and specify the page in xaml like this:

<local:ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                   xmlns:local="clr-namespace:XamarinFormsApp.Controls"
                   x:Class="XamarinFormsApp.Views.WelcomeView">

    <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />

</local:ContentPage>

This would (normally) work in xaml, but gives me this error in Xamarin.Forms:

Error   7   The "XamlG" task failed unexpectedly.
System.Exception: Can't load types from xmlns clr-namespace:XamarinFormsApp.Controls
   at Xamarin.Forms.Build.Tasks.XamlG.GetNamespace(String namespaceuri)
   at Xamarin.Forms.Build.Tasks.XamlG.GetType(String nsuri, String type, IList`1 typeArguments, Func`2 getNamespaceOfPrefix)
   at Xamarin.Forms.Build.Tasks.XamlG.GenerateFile(String xamlFile, String outFile)
   at Xamarin.Forms.Build.Tasks.XamlG.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() XamarinFormsApp.iOS

Is this (yet) unsupported or am I doing something wrong?

Était-ce utile?

La solution

this was fixed in Xamarin.Forms 1.0.6197 released on 2014-06-04.

also, your xmlns:local misses the assembly attribute. It should be xmlns:local="clr-namespace:XamarinFormsApp.Controls;assembly=XamarinFormsApp"

UPDATE: the assembly part in the xmlns is no longer required if you're loading types from the same assembly

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top