Page 1 of 1

WPF controls in PSS

Posted: Tue Aug 08, 2017 4:10 am
by Alex.ferrie
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Are there any plans to make WPF controls available within the PSS forms designer?

Re: WPF controls in PSS

Posted: Tue Aug 08, 2017 5:10 am
by Alexander Riedel
Not seamless, these are two incompatible technologies as far as the designer goes. WPF more or less requires you to write XAML, basically spelling everything out in XML.
You can use WPF controls with a Windows Form environment though. There is a control set "ElementHost – WPF Control Host" that you can add to your form to include WPF controls.

Re: WPF controls in PSS

Posted: Tue Aug 08, 2017 5:17 am
by Alex.ferrie
Hi Alex, thanks for the quick response. How do I then get access to the WPF controls?

Re: WPF controls in PSS

Posted: Tue Aug 08, 2017 5:29 am
by Alexander Riedel
I will let the expert answer this. Folks will be in later during normal office hours.

Re: WPF controls in PSS

Posted: Mon Aug 14, 2017 4:08 am
by Alex.ferrie
Hi Alex, not heard anything back. Do you want me to post this elsewhere?

Re: WPF controls in PSS

Posted: Mon Aug 14, 2017 4:15 am
by Alexander Riedel
Hmm, sorry, not sure what happened. The best person for this is out of office this week. I will make sure to send emails until he answers :D

Re: WPF controls in PSS

Posted: Mon Aug 21, 2017 7:53 am
by davidc
In order to access the controls within your XAML, you have to query the control and assign it to a variable.

Code: Select all

$script:WPFControl = Update-ElementHost -Elementhost $elementhost -XAML $xaml
	if($WPFControl)
	{
		$wpfButton = [System.Windows.Controls.Button]$WPFControl.FindName("WPFButton")
		
		if($wpfButton)
		{
			$wpfButton.Add_Click({Write-Host "WPF Button was clicked"})
		}
	}
If you want PowerShell Studio to provide PrimalSense, I recommend casting the object before assigning the variable:

$wpfButton = [System.Windows.Controls.Button]$WPFControl.FindName("WPFButton")

You may need to reference the WPF assembly first:
Add-Type -AssemblyName PresentationFramework
If you have the latest service release, you can set a breakpoint after the variable is assigned and PowerShell Studio will use the session state to provide PrimalSense.

For further GUI support, I recommend posting in the PowerShell GUIs forum:

viewforum.php?f=21