With the release of the latest service build (5.9.257), we have added support for XAML files in PowerShell Studio’s projects and have created a new project template named WPF Project. This is part of our ongoing process to add support for Windows Presentation Foundation (WPF).

WPF Project Template
When you create a project with the WPF Project template, it will include the following files:

- MainWindow.ps1: Logic for your window.
- MainWindow.xaml: Used for declaring and defining your WPF controls for your window.
- Startup.pss: Used for declaring or initializing anything before loading your window.
XAML Project File Settings
With the inclusion of XAML files in the project build process, new project file settings have been created:

PowerShell Build File
When this property is set, it will generate the WPF PowerShell initialization code for loading the XAML. No more than one XAML file can use a PowerShell file as a PowerShell Build File.
XAML Variable
Name of the variable to which the XAML is saved as a string. The name is generated based on the name of the XAML file.
WPF Variable
Name of the variable with the loaded XAML if the PowerShell Build File is set. The name is generated based on the name of the XAML file. This value is only applicable when the PowerShell Build File is set.
General Project File Settings
For existing project file settings, there are some changes to note:
- XAML files are now added with the Build setting set to ‘Include’ by default in projects.
- Any PowerShell file set as a XAML file’s PowerShell Build File will follow the XAML file when building, regardless of the Build Order of that PowerShell file. As Build Order is the order in which files are added to the generated project script, this can affect how you call this file.
- Only PS1 files with the Build setting with ‘Include’ can be set as the PowerShell Build File.
- When PowerShell Build File property is set, the Shared property of the PowerShell file is automatically switched to false. This cannot be changed.
For information on PowerShell Studio general project files settings, please refer to our PowerShell Studio Projects: Introduction article.
Generated Script
When building/running a project, the resulting script will contain code similar to the following:

All generated WPF code is added to the PowerShell Build File’s Reference Function. This includes code for loading the XAML, generating the control variables, and calling the window.
Currently, PowerShell variables are only generated for controls with the Name property defined. The generated control variables can be seen in PrimalSense auto completion:

At this time, these controls are only listed in the initial auto-complete prompt. There are plans for a future release to improve this functionality.
Reference Function
Generally, a PowerShell file with the Build setting to ‘Include’, a Reference Function is created with the following name:
Invoke_[File Name]_ps1
The Reference Function for PS1 files set as a XAML’s build file will look like the following:
Show_[File Name]_ps1
This follows the same naming convention as when all the reference functions for a PowerShell Studio Form (PSF) file.
Calling this function will open the Window. This function can be called from all files in the project with the Build Setting set to ‘Include’.
For the default files of a WPF project, the reference function for MainWindow.ps1 is called Show-MainForm_ps1. The call to this reference function is in Startup.pss:

Feedback
As always, any feedback is appreciated. If you have a particular type of blog article or product feature request you would like to see, please submit your suggestions on the Wish List and Feature Requests forum or the Feature Requests page.