youyiyang 2022-10-15 09:55 采纳率: 74.2%
浏览 181
已结题

"myButton_Click" 没有与委托“RoutedEventHandler”匹配的重载

在做一个WPF的练习的时候,代码如下,有红色线报错

using System.Windows;
using System.Windows.Controls;
using System.IO;
using System.Windows.Markup;

namespace WpfApp2
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    public partial class MainWindow : Window
    {
        private Button myButton;
        public MainWindow()
        {
            InitializeComponent();
        }

        public MainWindow(string xamlFile)
        {
            this.Width = this.Height = 286;
            this.Left = this.Top = 100;
            this.Title = "Dynamically Loading XAML";

            DependencyObject rootElement;
            using (FileStream fs = new FileStream(xamlFile, FileMode.Open))
            {
                rootElement = (DependencyObject)XamlReader.Load(fs);
            }
            this.Content = rootElement;

            myButton = (Button)LogicalTreeHelper.FindLogicalNode(rootElement, "button1");

            myButton.Click += myButton_Click;
        }
        

        private void myButton_Click(object sender, RoutedEvent e)
        {
            myButton.Content = "Thank you.";
        }
    }
}
红色线报错在
myButton.Click += myButton_Click;
报错内容是:
void MainWindow.myButton_Click(object sender, RoutedEvent e)
"myButton_Click" 没有与委托“RoutedEventHandler”匹配的重载
请问是什么原因?谢谢

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 10月23日
    • 创建了问题 10月15日

    悬赏问题

    • ¥15 这个main已经在filename.obj中定义是什么错 C语言
    • ¥15 使用elementor设计样式
    • ¥15 springboot项目程序启动报错
    • ¥15 grlb复位后关闭硬限位开关,移动中仍然会触发停止。
    • ¥20 微信平台收付通的相关问题
    • ¥15 grbl复位后,移动会触发报警Alarm 1
    • ¥15 grbl为何无法移动到比复位坐标更小的坐标?
    • ¥15 pspice找元件和一个问题
    • ¥60 怎样隐藏win7系统进程?
    • ¥15 CBF预处理数据归一化的时候报错了如下图