gpt4 book ai didi

c# - WPF编译错误

转载 作者:行者123 更新时间:2023-12-02 10:45:42 28 4
gpt4 key购买 nike

我正在尝试学习.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="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>

像这样的C#代码:
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" />

以及相应的事件处理程序代码:
private void Exponent(object sender, RoutedEventArgs e)
{
process_operation((a, b) => System.Math.Pow(a, b));
}
private void Seven(object sender, RoutedEventArgs e)
{
process_input('7');
}

但是由于某些原因,我在指数上没有错误,但是在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# - WPF编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5602744/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com