-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWPF_CustomGraphicalInputBoxSample.ps1
More file actions
40 lines (32 loc) · 1.33 KB
/
Copy pathWPF_CustomGraphicalInputBoxSample.ps1
File metadata and controls
40 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName PresentationFramework
# 呼び出し元のカレントディレクトリに依存せず、スクリプトと同じ場所の XAML を読む。
$xamlPath = Join-Path $PSScriptRoot 'WPF_CustomGraphicalInputBoxSample.xaml'
[xml]$xaml = Get-Content -LiteralPath $xamlPath -Raw
# Visual Studio が追加する、単体の XamlReader では不要な属性を取り除く。
$xamlRoot = $xaml.DocumentElement
[void]$xamlRoot.RemoveAttribute('Class', 'http://schemas.microsoft.com/winfx/2006/xaml')
[void]$xamlRoot.RemoveAttribute('Ignorable', 'http://schemas.openxmlformats.org/markup-compatibility/2006')
$xamlReader = [System.Xml.XmlNodeReader]::new($xaml)
try {
[System.Windows.Window]$mainWindow = [System.Windows.Markup.XamlReader]::Load($xamlReader)
}
finally {
$xamlReader.Close()
}
[System.Windows.Controls.Button]$okButton = $mainWindow.FindName('OkButton')
[System.Windows.Controls.Button]$cancelButton = $mainWindow.FindName('CancelButton')
[System.Windows.Controls.TextBox]$textBox = $mainWindow.FindName('TextBox')
$okButton.Add_Click({
$mainWindow.DialogResult = $true
})
$cancelButton.Add_Click({
$mainWindow.DialogResult = $false
})
$result = $mainWindow.ShowDialog()
if ($result -eq $true) {
$textBox.Text
}