Building the Foundation for Windows Presentation
Before we get into today's topic, a few housekeeping items. In the last few articles, I took advantage of the attachment feature. I knew I couldn't send .ps1 files, so I attached a zip file. Unfortunately, if you have a Gmail address, the emails still bounced. It appears that Gmail is looking at the zip file contents and bouncing the email because the attachment contains forbidden files. If you missed them, you can find the articles on the archive page, including the zip file attachments. For now, I will stop using the attachment feature and will look for a better long-term solution. I also encourage you to ensure that the email addresses jhicks@jdhitsolutions.com and behind@jdhitsolutions.com are on your safe sender list.
In the recent articles that shared my toolmaking experiences building an archive summary/search solution for this newsletter, I showed a simple script that generated a GUI which allowed me to edit preview text. I created this script using PowerShell and Windows Presentation Foundation (WPF). Creating graphical PowerShell scripts always seems like a popular topic. WPF was built for .NET developers so it can be a bit daunting for PowerShell scripters. But I think it is worth the effort. In this new series of articles, I want to show you how to build a simple WPF GUI using PowerShell.
WPF is a .NET class library for building GUI applications. You might want to have a graphical front-end for a user to input data for a PowerShell command. Or maybe you want to present PowerShell-generated data in a user-friendly, graphical format. At its core, such a tool is running PowerShell code. The best practice is to write your PowerShell code first and confirm that it runs. Then build the GUI on top of it. This is the proper design pattern.
You may have seen other graphical scripts that use Windows Forms (WinForms). Window Forms shares some similarities with WPF, but WPF is the newer technology and is the preferred choice. The biggest difference is that WinForms doesn't scale well to different resolutions. WinForms worked better when we had older monitors and 1024x768 was considered a high resolution. WPF automatically scales to different resolutions and simply looks better.