我刚刚更新了我的应用程序中的软件包,但我收到了许多我不明白的此类新错误:
/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/