xamarin - XAML/cs - 更新包后,成员名称不能与其封闭类型 (CS0542) 相同

标签 xamarin xamarin.forms

我刚刚更新了我的应用程序中的软件包,但我收到了许多我不明白的此类新错误:

/Users/alan/Downloads/Japanese 31/Japanese/obj/Debug/Views/Help/GettingStarted.xaml.g.cs(51,51): 

Error CS0542: 'GettingStarted': member names cannot be the same as their enclosing type (CS0542) (Japanese)

我有看起来像这样的 XAML 代码;
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:Japanese;assembly=Japanese"
    x:Class="Japanese.GettingStarted"
    x:Name="GettingStarted" 
    Title="Getting Started">
<ContentPage.Content>

我的C#
using System;
using System.Collections.Generic;

using Xamarin.Forms;

namespace Japanese
{
    public partial class GettingStarted : ContentPage
    {
        public GettingStarted()
        {

我是否错误地编码了我的 XAML 和 cs?我认为这是使用部分类和相同的类名来做到这一点的方法。

最佳答案

x:Name="GettingStarted"这就是问题。这将是您的页面的名称,但它也是该页面的类的名称。为 x:Name 指定一个值属性在您的代码隐藏中创建一个具有该名称的变量。所以你会得到的是:GettingStarted GettingStarted = new GettingStarted();至少可以说这令人困惑。我猜 Xamarin 团队遇到了这些相同名称和类型的问题,并决定阻止它。

尝试使用不同的名称,或者,如果您不想使用不同的大小写,例如:x:Name="gettingStarted"

关于xamarin - XAML/cs - 更新包后,成员名称不能与其封闭类型 (CS0542) 相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51210658/

相关文章:

c# - DequeueReusableCell 仅在 iPhone 4S 上使应用程序崩溃

c# - 如何隐藏数字键盘,我使用的是 Xamarin iOS (C#)

c# - 附加属性或行为时,如何访问 xamarin 表单元素背后的 native 控件?

xaml - 在 ListView 的 StackLayout 中使用 TextCell

升级到 Xamarin Forms 2.0 后的 Android 资源问题

c# - Xamarin IOS 蓝牙 LE 广告

Android:MotionEvent 需要对 GetHistoricalX 和 GetHistoricalY 进行一些说明

c# - 带有行号的 Xamarin Insights

xamarin.forms - AcquireToken 一段时间后停止工作

c# - 在 Xamarin.Forms 页面中隐藏 iPhone X 的主页指示器