类型或名称空间名称“ Graphics”在名称空间“ Project.Android”中不存在

时间:2018-08-23 04:39:19

标签: xamarin xamarin.forms custom-renderer

我正在Xamarin.Forms应用程序上工作,在其中我添加了一个自定义渲染器来设置本机编辑文本的背景。以下代码显示错误。 var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());

1 个答案:

答案 0 :(得分:2)

问题是您的应用程序使用命名空间Project.Android,而类型系统会认为Android.Grapics.Drawables.Shapes.RectShape属于Project.Android

您有一些选择:

  1. 更改项目和所有类中的命名空间
  2. Android.Graphics.Drawables.Shapes.RectShape前面加上global::,例如:global::Android.Graphics.Drawables.Shapes.RectShape
  3. 在文件顶部添加一个用法,告诉RectShape的来源:using RectShape = Android.Graphics.Drawables.Shapes.RectShape,只需使用new RectShape()
相关问题