Erman Uruk
Erman Uruk

Reputation: 17

WPF MenuItem multi adding.

Error CS0120 An object reference is required for the non-static field, method, or property 'MainWindow.System' %Path%\MainWindow.g.cs at line 316

I get the code error i mentioned on title when i try to add Sub MenuItems under a SubMenuItem. Here is my Code:

<Menu x:Name="MainMenu" Height="Auto" Width="Auto" VerticalAlignment="Top">
                <MenuItem Header="_Menu" x:Name="Menu" Foreground="Black">
                    <MenuItem x:Name="RestartComputer" Header="_Restart Computer" Click="restart_Click"/>
                    <MenuItem x:Name="ShutdownComputer"  Header="_Shutdown Computer" Click="shutdown_Click"/>
                    <MenuItem x:Name="OnTop" Header="_Always On Top" Click="OnTop_Click"/>
                    <Separator Width="Auto" Height="2"/>
                    <MenuItem x:Name="Exit" Header="_Exit" Click="MenuItem_Click"/>
                </MenuItem>
                <MenuItem x:Name="ControlPanel" Header="_Control Panel" Height="Auto" Width="Auto" Foreground="Black">                    
                        <MenuItem x:Name="Main" Header="Control Panel Main"/>
                        <MenuItem x:Name="ProgramsAndFeatures" Header="Programs and Features"/>
                        <MenuItem x:Name="AdministrativeTools" Header="Administrative Tools"/>
                        <MenuItem x:Name="DeviceManager" Header="Device Manager"/>
                        <MenuItem x:Name="NetworkAndSharing" Header="Network and Sharing"/> 
                        <MenuItem x:Name="PowerOptions" Header="Power Options"/>
                        <Separator Width="Auto" Height="2"/>
                        <MenuItem x:Name="WindowsFirewall" Header="Windows Firewall"/>
                        <MenuItem x:Name="Display" Header="Display"/>
                        <Separator Width="Auto" Height="2"/>
                        <MenuItem x:Name="System" Header="System"/>
                        <MenuItem x:Name="DevicesAndPrinters" Header="Devices and Printers"/>                    
                </MenuItem>                
            </Menu> 

If i lessen these MenuItems under ControlPanel menu item to 4 or 5 no problem, but if i make them more than 5 or 6 i get the error what can it be ?

And also at MainWindow.g.cs line 316 is this.

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]

Upvotes: 1

Views: 102

Answers (1)

dhilmathy
dhilmathy

Reputation: 2868

Use different x:Name for

<MenuItem x:Name="System" Header="System"/>

Upvotes: 1

Related Questions