C# WPF编译错误
我正在尝试学习.NET和WPF,我正在制作一个计算器类型的应用程序来学习一些框架。我有如下XAML代码:C# WPF编译错误,c#,wpf,xaml,compiler-errors,C#,Wpf,Xaml,Compiler Errors,我正在尝试学习.NET和WPF,我正在制作一个计算器类型的应用程序来学习一些框架。我有如下XAML代码: <Window x:Class="CS_WPF_TEST.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="M
<Window x:Class="CS_WPF_TEST.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Margin="4" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" Name="DisplayBox" IsReadOnly="True" />
<Button Margin="4" Grid.Row="1" Grid.Column="0" Name="MC" Content="MC" Click="ClearMem" />
<Button Margin="4" Grid.Row="1" Grid.Column="1" Name="MR" Content="MR" Click="RecallMem" />
/snip/
<Button Margin="4" Grid.Row="6" Grid.Column="3" Name="Plus" Content="+" Click="Plus" />
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CS_WPF_TEST
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//snip
//event handlers with declarations like following
private void Handle(object sender, RoutedEventArgs e)
{
//code
}
}
}
<Button Margin="4" Grid.Row="2" Grid.Column="3" Name="Caret" Content="^" Click="Exponent" />
<Button Margin="4" Grid.Row="2" Grid.Column="4" Name="Sqrt" Content="Sqrt" Click="Sqrt" />
但出于某种原因,我在指数上没有错误,但在7上我得到了如下错误:
c:\snip\CS_WPF_TEST\CS_WPF_TEST\MainWindow.xaml(34,49): error CS0102: The type 'CS_WPF_TEST.MainWindow' already contains a definition for 'Seven'
C:\snip\CS_WPF_TEST\CS_WPF_TEST\MainWindow.xaml.cs(264,22): (Related location)
是我的语法错误,还是有什么我不知道的,比如事物在中声明的顺序还是什么?看起来您对XAML控件和事件处理程序使用了相同的名称。不要这样做。您的页面上是否有一个您命名为“七”的按钮?它可能与您的方法名称相冲突。
c:\snip\CS_WPF_TEST\CS_WPF_TEST\MainWindow.xaml(34,49): error CS0102: The type 'CS_WPF_TEST.MainWindow' already contains a definition for 'Seven'
C:\snip\CS_WPF_TEST\CS_WPF_TEST\MainWindow.xaml.cs(264,22): (Related location)