很奇怪......
有一个名为 Android.Graphics 的命名空间,我在名为 Xamarin.FormsBook.Platform.Android 的命名空间中工作。
还有一个名为 Xamarin.Forms 的命名空间,它有Color字段。
现在,我想使用 Android.Graphics.Color ,所以我写了Color然后把它识别为 Xamarin.Forms.Color 而不是 Android.Graphics。颜色
而且,如果我写 Android.Graphics.Color ,则构建器找不到Android.Graphics。如果我写Android。然后构建器找到 Xamarin.FormsBook.Platform.Android 的方法和字段。
如果我在命名空间区域之外写 Android.Graphics.Color ,那么它就会识别。
但我无法在其中分配任何值,因为'命名空间不能直接包含字段或方法等成员'。
帮助我,我想使用Color of Android.Graphic
答案 0 :(得分:1)
您可以使用alias directive:
来完成此操作using AndroidGraphics = Android.Graphics;
然后,您可以使用别名Android.Graphics.Color
来引用AndroidGraphics.Color
类型。由于没有另一个名为AndroidGraphics
的命名空间,您的编译器将正确解析它。
Alias指令也可用于各种类型,因此您还可以执行以下操作:
using AndroidColor = Android.Graphics.Color;
然后使用AndroidColor
引用类型。