wpf 成员名称不能与其在 g.cs 文件中的封闭类型相同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23326569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:39:16  来源:igfitidea点击:

member names cannot be the same as their enclosing type in g.cs file

c#wpfxaml

提问by grizzo

I've already searched for a solution to this problem in StackOverflow but apparently this time is different. In my Windows Phone application when the user presses a specific button the app should redirect him to a specific Panorama Page so I followed this how to:

我已经在 StackOverflow 中搜索过这个问题的解决方案,但显然这次不同。在我的 Windows Phone 应用程序中,当用户按下特定按钮时,该应用程序应将他重定向到特定的全景页面,因此我按照以下方法操作:

http://blogs.msdn.com/b/aschapiro/archive/2012/07/21/navigating-directly-to-a-specific-screen-inside-a-panorama-or-pivot-page.aspx

http://blogs.msdn.com/b/aschapiro/archive/2012/07/21/navigating-directly-to-a-specific-screen-inside-a-panorama-or-pivot-page.aspx

But when I compile the solution this error appears:

但是当我编译解决方案时出现此错误:

'donazione': member names cannot be the same as their enclosing type

'donazione':成员名称不能与其封闭类型相同

But this error is in the .g.cs file o the donazione.xaml file created during the compilation, so I looked at it and the error is:

但是这个错误是在编译过程中创建的donazione.xaml文件的.g.cs文件中,所以我查看了一下,错误是:

namespace Avis {


public partial class donazione : Microsoft.Phone.Controls.PhoneApplicationPage {

    internal System.Windows.Controls.Grid LayoutRoot;

    internal Microsoft.Phone.Controls.Panorama donazione; <-- the error is in this line

    private bool _contentLoaded;

    /// <summary>
    /// InitializeComponent
    ....

Obviuously trying to modify this file wouldn't solve anything so here it is the donazione.xaml file which causes this error:

显然,尝试修改此文件并不能解决任何问题,因此这里是导致此错误的 donazione.xaml 文件:

<phone:PhoneApplicationPage
x:Class="Avis.donazione"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"  Orientation="Portrait"
shell:SystemTray.IsVisible="False">

<Grid x:Name="LayoutRoot">
    <controls:Panorama x:Name="donazione">

        <!--Panorama item one-->
        <controls:PanoramaItem Header="Il sangue">
            <Grid/>
        </controls:PanoramaItem>

        <!--Panorama item two-->
        <controls:PanoramaItem Header="Perché Donare">
            <Grid/>
        </controls:PanoramaItem>
        <controls:PanoramaItem Header="Chi può donare">
            <Grid/>
        </controls:PanoramaItem>
        <controls:PanoramaItem Header="Come donare">
            <Grid/>
        </controls:PanoramaItem>
        <controls:PanoramaItem Header="Tipi di donazione">
            <Grid/>
        </controls:PanoramaItem>
        <controls:PanoramaItem Header="FAQ">
            <Grid/>
        </controls:PanoramaItem>
    </controls:Panorama>
</Grid>

I confronted it with the how-to's ones but, except for the additional elements, the initial declarations are equal.

我用操作方法来解决它,但是,除了附加元素之外,初始声明是相等的。

Anybody can help me? Thanks.

任何人都可以帮助我吗?谢谢。

采纳答案by Aybe

You can't have a member in your class which is named like your class is.

你的班级中不能有一个像你的班级那样命名的成员。

Example :

例子 :

class Test
{
    int Test; // error
    int Test1; // OK
}

Solution:

解决方案

  • change the name of donazionevariable to something else.
  • now since it is a .g.cs file you should do that from the design-view properties window
  • donazione变量的名称更改为其他名称。
  • 现在因为它是一个 .g.cs 文件,你应该从设计视图属性窗口中执行此操作

回答by Paul T

If this is via the Main StoryBoard it is quite likely the same name has been typed into the View and View Controller (by mistake given the latency in the Main StoryBoard) - remove the name from the View

如果这是通过主故事板,很可能在视图和视图控制器中输入了相同的名称(由于主故事板中的延迟,这是错误的) - 从视图中删除名称