在做一个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”匹配的重载
请问是什么原因?谢谢