Part 1: Create WPF XAML powershell GUI form with Visual studio
Part 2: Powershell and WPF: Build GUI applications tutorial
Last month in pune, India, I got an opportunity to present a small offline webinar for around 10 to 15 users, I was preparing for this session and couldn't write much on my blog in the month of February. This seminar was regarding building Powershell GUI using WPF. In this first part, I shown how to create a XAML GUI form, which I can easily use in powershell with few modification. Before designing a form I always use pen and paper to know, how my GUI will look like. Below is my ruff design, Sorry for the bad handwriting and straight lines :).
Here I wanted to show easier way to create and didn't want to code for the same, its time to create XAML code of above design, First of all, there is a requirement of Visual Studio Community Edition to be installed, It can be downloaded from https://www.visualstudio.com/vs/community. It is free. Below are the system prerequisite to install the software.
Visual Studio Community 2015 with Update 3 Hardware Requirements
| Windows 10 Windows 8.1 Windows 8 Windows 7 SP 1 Windows Server 2012 R2 Windows Server 2012 Windows Server 2008 R2 SP1 |
Once software is launched, We will create a new WPF Application project by clicking File menu >> New >> Project. In the New Project, Under Templates>>Visual C# Search for WPF Application (Type C#), This is a Windows Presentation Foundation Client application and click OK.
This shows a Empty form on the design view, Expand ToolBox on the Left, then select the WPF controls, drag and drop them in the form, then Resize and align them accordingly. I have used 4 wpf controls here.
0: Label - Computer or IP
1: TexBox - Input Box
2: Button - This is action button, Once it is pressed information is processed
3: Grid - In this table information will be shown.
Once all the controls in place, I want to give them user friendly and meaningful name which I will be using in Powershell when I start actual coding, for this choose properties of each control and provide it a name in the right hand side bottom corner, you can select color and other stuffs here, I am keeping everything default and as simple as possible with less options.
Once complete form is built, you can see the GUI code in bottom, copy this code.
I can not use this complete code, and need to remove few lines and items from the code, first copy the code in notepad, I have highlighted in darkgrey, which needs to be removed. Lines can be removed straightly, another thing I don't require x: in front of Name, which I can replace all with empty, nothing. In the bottom their is usable code highlighted as yellow. This I will use in next article where actually I will write powershell codes.
I can write another PowerShell function to remove unwanted part from this, but I want to show here what we don't require here.
Other Powershell GUI blogs
COOL POWERSHELL FREE ONLINE GUI GENERATOR TOOL, POSHGUI
Generate random password GUI using powershell