Failed to create WPF event handler

I cannot create an event handler when I double-click a button or anything that appears in this post enter image description here

as ever when I add an event handler manually, it works. Any idea what I could ruin thanks

+3
source share
4 answers

The class in question is the "MainWindow" class inside your file MainWindow.xaml.cs. Make sure this is the first class in the code behind the file.

I suspect that you added another type to this file and defined it at the top. It will “break” the constructor and provide you with this error message.

+12
source

.CS, .

+3

Move the class code so that it is the first class in the file and try again.

+2
source

If you renamed a window, make sure that it also affected the code behind the file, as you can see in the xaml designer code. Compare the class name and window name in all places. I had the same problem, and I noticed that when I renamed the window, the associated code behind the class name was not updated automatically. So I did it manually, and everything went well. Hope this helps :)

0
source

Source: https://habr.com/ru/post/1794301/


All Articles