'Xamarin.Forms.Label' 和 'System.Reflection.Emit.Label' 之间的模糊引用
Ambiguous reference between 'Xamarin.Forms.Label' and 'System.Reflection.Emit.Label'
我将在 Visual Studio 2015 年 Windows 开始我的第一个 Xamarin.Forms 应用程序。
我的启动项目是 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' is an ambiguous reference between 'Xamarin.Forms.Label' and 'System.Reflection.Emit.Label'
我应该怎么做才能解决这个问题?
要么从 SensorPage.cs 的顶部删除 using System.Reflection.Emit;
,要么为标签使用显式命名空间:
Content = new StackLayout {
Children = {
new Xamarin.Forms.Label { Text = "Hello SensorPage" }
}
};
我将在 Visual Studio 2015 年 Windows 开始我的第一个 Xamarin.Forms 应用程序。
我的启动项目是 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' is an ambiguous reference between 'Xamarin.Forms.Label' and 'System.Reflection.Emit.Label'
我应该怎么做才能解决这个问题?
要么从 SensorPage.cs 的顶部删除 using System.Reflection.Emit;
,要么为标签使用显式命名空间:
Content = new StackLayout {
Children = {
new Xamarin.Forms.Label { Text = "Hello SensorPage" }
}
};