Define xmlns in Xamarin Forms

时间:2016-04-25 09:07:17

标签: c# xaml xamarin xamarin.forms

I have created a Xamarin Forms application. I created another PCL library for keeping UI constants like Color codes.

Portable project name is App. PCL library project is Utilities. Defined this in my PCL lib

namespace App.Utilities
{
    public class Colors
    {
        public static Color ColorCode1 = Color.Aqua;
    }
}

Tried to define xmlns in xcml file like this.

xmlns:colors="clr-namespace:App.Utilities.Colors;assembly=App.Utilities"

But it is throwing xaml parse exception saying the above namespace cannot be found.

Any help?

1 个答案:

答案 0 :(得分:3)

XMLNS declaration syntax is correct. Namespace need not include the class name. So In this case Namespace has to be just App.Utilities and not App.Utilities.Colors. Changing it to

xmlns:colors="clr-namespace:App.Utilities;assembly=App.Utilities"

will work provided your assembly name is correct.

You can verify if your assembly name is correct by Right-Clicking on PCL Forms prject > Options > Output (Under Build). There we can see the correct assembly name.

enter image description here