本文介绍了在Xamarin表单中定义xmlns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Xamarin Forms应用程序.我创建了另一个PCL库来保持UI常量(如颜色代码).

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

便携式项目名称为App.PCL库项目是实用程序. 在我的PCL库

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;
    }
}

试图像这样在xcml文件中定义xmlns.

Tried to define xmlns in xcml file like this.

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

但是它抛出了xaml解析异常,表明找不到上述名称空间.

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

有帮助吗?

推荐答案

XMLNS声明语法正确.命名空间不必包含类名.因此,在这种情况下,命名空间必须仅为App.Utilities而不是App.Utilities.Colors.将其更改为

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.

您可以通过右键单击PCL Forms prject>选项>输出(正在构建)来验证程序集名称是否正确.在那里,我们可以看到正确的程序集名称.

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.

这篇关于在Xamarin表单中定义xmlns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:02
查看更多