我刚刚更新了我的应用程序中的包,并且我收到了许多这种类型的新错误,我不明白:
/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编码错误吗?我认为这是用部分类和同一个类名来实现这一目的的方法。
发布于 2018-07-06 12:41:52
x:Name="GettingStarted",这就是问题所在。这将是您的页面的名称,但它也是该页面的类的名称。为x:Name属性指定一个值将在代码隐藏中创建一个具有该名称的变量。所以,您将得到的是:GettingStarted GettingStarted = new GettingStarted();,至少可以说,这是令人困惑的。我猜Xamarin团队遇到了这些相同的名称和类型的问题,并决定阻止它。
尝试想出一个不同的名称,或者,如果您不想使用不同的大小写,比如:x:Name="gettingStarted"
发布于 2021-10-19 09:24:13
这发生在我试图在*.xaml.cs中重命名XAML的类文件时
我发现了一个简单的修复方法:
https://stackoverflow.com/questions/51210658
复制相似问题