WPF event (click) handler won't add the code behind to the class and displays an Error in VS 2022 Shared Project

Sean Page 0 Reputation points
2023-07-05T12:24:14.2066667+00:00

I have a solution with two (C# .NET Framework 4.8) DLL library projects and a Shared Project. When I try to add a WPF User Control (Window) to the shared project, I am unable to create any event handlers to the code behind. I am able to get Data Context and bindings as well as navigate (F12) to the associated partial class, but receive and error as shown in the images any time I try to add any event handlers. This is specifically true for buttons and checkboxes.

Thank you in advance for any help or guidance!

Here I am trying to add a Checked event handler to a Checkbox:User's image

Error Message Saying "Failed to Create Event Handler"

User's image

Here you can also see that the Code Behind class is not "nesting" with the User Control XAML

User's image

Here is the Code behind where you can see no Event handler was created:

User's image

Developer technologies | Windows Presentation Foundation
Developer technologies | Visual Studio | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,681 Reputation points Microsoft External Staff
    2023-07-06T08:52:11.7966667+00:00

    Hi,@Sean Page. I reproduced your problem. It is a bug. When click <New Event Handler > of Checked code IntelliSense can generate event in Microsoft Visual Studio Community 2019 Version 16.11.27.

    When click <New Event Handler > of Checked code IntelliSense , get error <Failed to create Event Handler> in Microsoft Visual Studio Professional 2022 Version 17.6.4 /Microsoft Visual Studio Community 2022 (64-bit) - Current

    It is recommended that you report questions on Developer Community.

    Before fixing the issue, you could add events manually. Or create a new WPF Class Library project (.NET Framework 4.8) to house your visual elements.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.