Ambiguous reference between 'Xamarin.Forms.Label' an
本文关键字:Label an Forms Xamarin Ambiguous reference between | 更新日期: 2023-09-27 18:19:22
我开始我的第一个Xamarin。
我的启动项目是firstApp.Droid。
在MainActivity.cs在firstApp。Droid我有这个代码:
namespace firstApp.Droid
{
[Activity (Label = "firstApp", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
LoadApplication (new firstApp.App ());
}
}
}
在App.cs我有这个代码:
public App ()
{
// The root page of your application
MainPage = new NavigationPage(new SensorPage());
}
在SensorPage.cs我有这个自动生成的代码:
public class SensorPage : ContentPage
{
public SensorPage ()
{
Content = new StackLayout {
Children = {
new Label { Text = "Hello SensorPage" } //line that causes the error
}
};
}
}
当我尝试编译应用程序时,我得到错误:
CS0104 'Label'是在'Xamarin.Forms. '之间的一个模糊引用。标签'和'System.Reflection.Emit.Label'
我该怎么做才能解决这个问题?
要么从SensorPage.cs的顶部删除using System.Reflection.Emit;
,要么为Label使用显式命名空间:
Content = new StackLayout {
Children = {
new Xamarin.Forms.Label { Text = "Hello SensorPage" }
}
};