WPF+PowerShell制作單機(jī)版應(yīng)用-創(chuàng)新互聯(lián)

我接觸到的PowerShell GUI化工具制作有三種方式
一.Web-------------B/S架構(gòu)
二.WPF------------C/S架構(gòu)
三.WinForm-------C/S架構(gòu)

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的興山網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

一.Web
詳見(jiàn)我的另一篇 https://blog.51cto.com/640006/2059918

二.WPF
WPF介紹,可以參考 http://liutiemeng.blog.51cto.com/120361/91631/
簡(jiǎn)單說(shuō)就是用來(lái)做GUI的,用的XAML,支持?jǐn)?shù)據(jù)綁定。而XAML本質(zhì)上就是XML,
PowerShell可以很方便的操作XML對(duì)象,這樣就能實(shí)現(xiàn)PowerShell和WPF結(jié)合。國(guó)外有不少這方面的帖子,不過(guò)很多都比較老,不再更新了。
https://foxdeploy.com/series/learning-gui-toolmaking-series/ 上有很詳細(xì)的PowerShell+WPF的說(shuō)明和介紹。最近的更新還加入了多線程。里面也有WinForm的教程。
簡(jiǎn)單總結(jié)下就是:
1.在vs studio下用XAML做好GUI界面。

2.把XAML代碼直接粘貼到下面PowerShell代碼的@""@里,或者XAML另存為一個(gè)文件,然后在PowerShell代碼里用Get-Content加載進(jìn)來(lái)也可以。

3.下面是用PowerShell操作XAML的代碼,foxdeploy已經(jīng)寫(xiě)好的模板,直接拿來(lái)用就行。這里面沒(méi)寫(xiě)事件控制,具體的看foxdeploy博客吧,和WinForm的一樣。

#ERASE ALL THIS AND PUT XAML BELOW between the @" "@
$inputXML = @"
<Window x:Class="Azure.Window1" 
    xmlns="http://schemas.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>
"@       

$inputXML = $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 there are NO SelectionChanged properties (PowerShell cannot process them)"
    throw}

#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================

$xaml.SelectNodes("http://*[@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 "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}

Get-FormVariables

#===========================================================================
# 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.運(yùn)行powershell腳本文件就可以了
上個(gè)圖,這個(gè)是參考彪鍋的WinForm版的樣子做的
WPF+PowerShell制作單機(jī)版應(yīng)用

5.記得VS studio的這個(gè)插件PowerShell Tools Pro,可以直接在VS studio中進(jìn)行PowerShell+WPF的開(kāi)發(fā),原理和上面都是一樣的,只不過(guò)是封裝了很多的函數(shù)。

三.WinForm
WinForm是微軟舊的GUI技術(shù)。和PowerShell結(jié)合方面與WPF很類似,只不過(guò)GUI不是用XAML來(lái)寫(xiě)。最簡(jiǎn)單的方法就是用Powershell Studio這個(gè)工具來(lái)做,看名字就知道了,專門用于PowerShell圖形化工具制作用的。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)頁(yè)標(biāo)題:WPF+PowerShell制作單機(jī)版應(yīng)用-創(chuàng)新互聯(lián)
文章起源:http://bm7419.com/article46/ddjheg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航商城網(wǎng)站、營(yíng)銷型網(wǎng)站建設(shè)、用戶體驗(yàn)、關(guān)鍵詞優(yōu)化、虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)