-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample-of-PowerShell-GUI.ps1
More file actions
91 lines (80 loc) · 2.12 KB
/
Copy pathExample-of-PowerShell-GUI.ps1
File metadata and controls
91 lines (80 loc) · 2.12 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function Convert-XAMLtoWindow
{
param
(
[Parameter(Mandatory=$true)]
[string]
$XAML,
[string[]]
$NamedElements,
[switch]
$PassThru
)
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
$reader = [System.XML.XMLReader]::Create([System.IO.StringReader]$XAML)
$result = [System.Windows.Markup.XAMLReader]::Load($reader)
foreach($Name in $NamedElements)
{
$result | Add-Member NoteProperty -Name $Name -Value $result.FindName($Name) -Force
}
if ($PassThru)
{
$result
}
else
{
$result.ShowDialog()
}
}
$xaml = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinHeight="350"
Width="525"
SizeToContent="Height"
Title="PowerShell WPF Window"
Topmost="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
<ColumnDefinition Width="30*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="20*"/>
</Grid.RowDefinitions>
<TextBlock
Name="TextMessage"
Grid.Column="1"
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="Consolas"
FontSize="20"
FontWeight="Bold"
Foreground="Blue">Hello World
</TextBlock>
<Button
Name="OK"
Width="80"
Height="25"
Grid.Column="2"
Grid.Row="2"
HorizontalAlignment="Right"
Margin="10"
VerticalAlignment="Bottom">OK
</Button>
</Grid>
</Window>
'@
$window = Convert-XAMLtoWindow -XAML $xaml -NamedElements 'TextMessage', 'OK' -PassThru
$window.ok.add_click({
$window.close()
}
)
$window.ShowDialog()