・Width、Height 固定値
・MinWidth, MaxWidth, MinHeight, MaxHeight 変動値
実行例
- PowershellだけでWPF表示(Powershell3.0でも2.0でも稼働)
- .Netframeworkは3.0以上が必要
- WPFの約束としてPowershellはSTAモードで動く必要あり
- 以下コードを
①Powershellコンソールにコピペして実行
②ISEで実行する時はすでにSTAモードなので適時修正して実行
注意:ブラウザによってはコピペで行頭に余分な空白が出来てしまうことあり
C:\temp> □'@ ← ここの行の行頭に空白あると動かない
(画像ファイル:"c:\temp\work\flower.jpg"を利用)
--------------------------------------------------------------
if ($host.Version.Major -eq 3) {
powershell.exe
} else {
if ($host.Runspace.ApartmentState -eq "STA") {return}
powershell.exe -version 2 -sta
}
$xaml_win = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="400">
<StackPanel>
<Button MinWidth="125" MaxWidth="200">Short Button String</Button>
<Image Width="250" Source="c:\temp\work\Flower.jpg"></Image>
<Button>Long Button String</Button>
</StackPanel>
</Window>
'@ # <--ブラウザによっては、コピペ時に行頭に空白出来る。空白削除する必要あり
if ($host.Version.Major -eq 3) {
add-type -assembly WindowsBase,PresentationCore,PresentationFramework,System.Xml,System.Xaml
} else {
add-type -assembly WindowsBase,PresentationCore,PresentationFramework,System.Xml
}
$form = [System.Windows.Markup.XamlReader]::Parse($xaml_win)
[void]$Form.ShowDialog()
exit
--------------------------------------------------------------
0 件のコメント:
コメントを投稿