最近会社でPowerShellを使うことになってきたので、
WPFでのGUIに挑戦してみました。

案外普通に使えるのでびっくり。
↓のようなコードで簡単に使えます。

ただし、powershell.exeを-Staで起動しないとだめなようですが。


Add-Type -AssemblyName "PresentationCore","PresentationFramework","WindowsBase"

$xaml = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <StackPanel>
    <Label Name="表示"/>
    <Button Name="ボタン">ボタン</Button>
  </StackPanel>
</Window>
"@

$win = [System.Windows.Markup.XamlReader]::Parse($xaml)
$win.FindName("ボタン").add_Click.Invoke({$win.FindName("表示").Content += "クリックされた"})

$win.ShowDialog()