Tool: Visual Studio, Visual Studio Code, PSScriptPad, PowerShell Module
Version:
I’m trying Pro Tools now and having issues with the WPF designer. The first issue is that when I try to subscribe to event handlers, the property window tells me there’s no code-behind file.
I tried manually typing out all of the methods in this article including Add-ControlVariables and Set-EventHandler. The methods run and the button instance is obtained but the event can’t be subscribed. Instead this error is generated:
[ERROR] Method invocation failed because [System.Windows.Controls.Button] does not
[ERROR] contain a method named 'addClick'.
[ERROR] At
[ERROR] C:\Users\xxxx\Code\xxxx\TrialAutomation\TAGui\NewUserWindow.xaml.ps1:22
[ERROR] char:2
[ERROR] + $AddUserButton.addClick({
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : InvalidOperation: (:) [], RuntimeException
[ERROR] + FullyQualifiedErrorId : MethodNotFound
[ERROR]
[ERROR] The pipeline has been stopped.
[ERROR] + CategoryInfo : OperationStopped: (:) [], PipelineStoppedException
[ERROR] + FullyQualifiedErrorId : PipelineStopped
The error message is accurate in that System.Windows.Button does not have an addClick method. It does inherit the Clickevent, but that class also doesn’t have an addClick method.
Is there a reason why the WPF designer is not finding the code-behind file?
What is the proper way to subscribe to the click event without help from the designer?
I realized that I was missing two important pieces.
It appears the designer automatically generates a line of code that looks for the button and removes the ‘Click’ attribute. I had missed that line and needed to type it in.
The method was actually add_Click not addClick.
I think both of these would have been done correctly if the designer was correctly working to generate code in the code-behind. Would love to figure out what’s wrong and get that working.
The reason this is happening, I think, is because the control you are editing doesn’t have a name defined. Try adding a name to and then see if the event handlers can be generated correctly.
Got it working. This was starting from a fresh install of Visual Studio Community 2019:
First install had .NET desktop app and UWP development workloads selected, but compared to the feature set listed in the above thread, I was missing F# desktop language support and SQL Server Express 2016 LocalDB. .NET also had the ML.NET Model Builder included by default. This setup produced the error listed.
My 2nd attempt was to add the two missing features, F# support and the SQL LocalDB. This still produced the same error, but I also tried to launch the WPF window with F5 and received an error stating “powershell tools for visual studio host has not started” - not sure if that was related.
Final attempt was to mirror the feature list exactly, including removing the UWP workload and the ML.NET Model Builder from the .NET workload. Once that install was done, I did see the event list show up for WPF controls.
Glad to see @swoot got it working, but I’m confused what the missing dependency is. It looks like things didn’t start working for swoot until he removed the UWP workload entirely and removed ML.Net Model Builder.
And since I do HoloLens development, I can’t uninstall the entire UWP workload. That will be something that a lot of developers won’t be able to uninstall.
I’m not 100% sure yet. The .NET Development workload used to be enough to cover all of PoshTools features but it looks like something has changed there and we need to identify the exact dependencies required here.
I don’t know why UWP’s removal would cause it to start working. That seems counterintuitive.