Wpf+powershell making a standalone application

Source: Internet
Author: User

I have access to the PowerShell GUI tools made in three ways
I. WEB-------------b/S architecture
Two. WPF------------c/S architecture
Three. WinForm-------C/S architecture

A. Web
See my other article on http://blog.51cto.com/640006/2059918

Two. WPF
WPF introduction, you can refer to http://liutiemeng.blog.51cto.com/120361/91631/
In short, it is used to do the GUI, in XAML, to support data binding. And XAML is essentially XML,
PowerShell makes it easy to manipulate XML objects, which enables PowerShell and WPF to be combined. Abroad there are many of these posts, but many are older, no longer updated.
Https://foxdeploy.com/series/learning-gui-toolmaking-series/has a very detailed description and introduction of POWERSHELL+WPF. The most recent update also added multithreading.
The Simple summary is:
1. Use XAML to do a GUI interface under vs Studio.

2. Paste the XAML code directly into the @ "" @ of the PowerShell code below, or save the XAML as a file and load it in the PowerShell code with get-content.

3. Here is the code for manipulating XAML with PowerShell, foxdeploy the templates that have been written, and just use them.

#ERASE all this and PUT XAML BELOW between the @ "" @ $inputXML = @ "<window x:class=" Azure.window1 "xmlns=" Http://sch Emas.microsoft.com/winfx/2006/xaml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:d= "http://schemas.microsoft.com/expression/blend/2008" xmlns:mc= "http://schemas.openxmlformats.org/ markup-compatibility/2006 "xmlns:local=" Clr-namespace:azure "mc:ignorable=" D "title=" IVision Azure Accelerator "Height=" 524.256 "width=" 332.076 "> <grid margin=" 0,0,174,0 "> </Grid></Window>" @ $inp Utxml = $inputXML-replace ' mc:ignorable= "D" ', '-replace ' x:n ', ' N '-replace ' ^<win.* ', ' <window ' [void][ System.reflection.assembly]::loadwithpartialname (' PresentationFramework ') [XML] $XAML = $inputXML #read XAML $reader = (New-object System.Xml.XmlNodeReader $xaml) try{$Form =[windows.markup.xamlreader]::load ($reader)}catch{ Write-warning "Unable to parse XML, with Error: $ ($Error [0]) ' n Ensure that thereIs NO selectionchanged properties (PowerShell cannot process them) "throw}#========================================== =================================# Load XAML Objects in powershell#================================================ =========================== $xaml. SelectNodes ("//*[@Name]") | %{"Trying Item $ ($_.    Name) "; try {set-variable-name "wpf$ ($_. Name) "-value $Form. FindName ($_. Name)-erroraction Stop} Catch{throw}}function get-formvariables{if ($global: Readmedisplay-ne $true) {write-host "I f you need to reference this display again, run Get-formvariables "-foregroundcolor Yellow; $global: readmedisplay= $true}WR Ite-host "Found The following interactable elements from our form"-foregroundcolor cyanget-variable wpf*}get-formvariabl es#===========================================================================# Actually make the objects work#==== ======================================================================= #Sample entry of how to add data to a field#$ VmpicklistviEW.ITEMS.ADD ([pscustomobject]@{' VMName ' = ($_). Name; Status=$_. Status;other= "Yes"}) #===========================================================================# Shows the form# ===========================================================================write-host "To show the form, run the Following "-foregroundcolor Cyan ' $Form. ShowDialog () | Out-null ' $Form. ShowDialog () | Out-null

4. Running the PowerShell script file is possible.
Last picture, this is a reference to the WinForm version of the Puma.

5. Remember that this plugin for vs Studio, PowerShell Tools Pro, can be powershell+wpf directly in VS Studio, the same principle as above, except that it encapsulates a lot of functions.

Three. WinForm
WinForm is Microsoft's old GUI technology. The combination with PowerShell is similar to WPF, except that the GUI is not written in XAML. The simplest way to do this is to use the PowerShell Studio tool, which is known for its name, and is specifically designed for use with the PowerShell graphical tool.

Wpf+powershell making a standalone application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.