-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUIControl.ps1
More file actions
219 lines (181 loc) · 6.36 KB
/
UIControl.ps1
File metadata and controls
219 lines (181 loc) · 6.36 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#########################################################################
# Author: Kevin RAHETILAHY #
#########################################################################
# =======================================================================
# Template Form and Node
#
# SUMMARY: This document helps you to re-use directly some common node in
# the XAML form without specifing it everytime.
# Make sure that names are different for each node of the same type
# you use to avoid conflict during the Control generation.
# =======================================================================
# ======================== Grid =======================================
Function New-Grid{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Margin)
$Grid = New-Object System.Windows.Controls.Grid
$Grid.Name = $Name
$Grid.Margin = $Margin
return $Grid
}
# =================== StackPanel ========================================
Function New-StackPanel{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[string] $Name,
[Parameter(Position=1)]
[string] $Margin,
[Parameter(Position=2)]
[string] $Orientation,
[Parameter(Position=3)]
[string] $HorizontalAlignment,
[Parameter(Position=4)]
[string] $Background
)
$StackPanel = New-Object System.Windows.Controls.StackPanel
if($Name){$StackPanel.Name = $Name}
$StackPanel.Orientation = $Orientation
$StackPanel.Margin = $Margin
$StackPanel.VerticalAlignment = "Stretch"
if($Background){$StackPanel.Background = $Background}
if($HorizontalAlignment){$StackPanel.HorizontalAlignment = $HorizontalAlignment}
return $StackPanel
}
# =================== RadioButton ======================================
Function New-RadioButton{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Margin,
[Parameter(Position=2,Mandatory=$true)]
[string] $GroupName)
$RadioButton = New-Object System.Windows.Controls.RadioButton
$RadioButton.Name = $Name
$RadioButton.Margin = $Margin
$RadioButton.GroupName = $GroupName
return $RadioButton
}
# ======================== Label =======================================
Function New-Label{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Margin,
[Parameter(Position=2)]
[string] $FontSize
)
$Label = New-Object System.Windows.Controls.Label
$Label.Name = $Name
$Label.Margin = $Margin
if ($FontSize){$Label.FontSize=$FontSize}
return $Label
}
# ======================== TextBlock =======================================
Function New-TextBlock{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[string] $Margin,
[Parameter(Position=1)]
[string] $FontSize,
[Parameter(Position=2)]
[string] $Foreground
)
$Label = New-Object System.Windows.Controls.TextBlock
$Label.Margin = $Margin
if($Foreground){$Label.Foreground = $Foreground}
if ($FontSize){$Label.FontSize=$FontSize}
return $Label
}
# ======================== Image =======================================
Function New-Image{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Size,
[Parameter(Position=2)]
[string] $Margin)
$Image = New-Object System.Windows.Controls.Image
$Image.Name = $Name
if($Margin -ne "") {$Image.Margin = $Margin }
$Image.Width =$Size.Split(",")[0]
$Image.Height=$Size.Split(",")[1]
$Image.HorizontalAlignment="Left"
$Image.VerticalAlignment="Top"
return $Image
}
# ======================== Border =======================================
Function New-Border{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Color)
$Border = New-Object System.Windows.Controls.Border
$Border.BorderBrush = $Color
$Border.BorderThickness = 2
return $Border
}
# ======================== Button =======================================
Function New-Button{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Margin,
[Parameter(Position=2,Mandatory=$true)]
[string] $Content,
[Parameter(Position=3,Mandatory=$true)]
[string] $Foreground)
$Button = New-Object System.Windows.Controls.Button
$Button.Name = $Name
$Button.Content = $Content
$Button.Margin = $Margin
$Button.Foreground = $Foreground
return $Button
}
# ======================== Progressbar =======================================
Function New-Progressbar{
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true)]
[string] $Name,
[Parameter(Position=1,Mandatory=$true)]
[string] $Margin,
[Parameter(Position=2,Mandatory=$true)]
[string] $Height)
$Progressbar = New-Object System.Windows.Controls.Progressbar
$Progressbar.Name = $Name
$Progressbar.Margin = $Margin
$Progressbar.Height = $Height
return $Progressbar
}
# ======================== Rectangle =======================================
Function New-Rectangle{
[CmdletBinding()]
param(
[Parameter(Position=0)]
[string] $Margin,
[Parameter(Position=1,Mandatory=$true)]
[string] $Size,
[Parameter(Position=2)]
[System.Windows.Media.VisualBrush] $VisualBrush
)
$Rectangle = New-Object System.Windows.Shapes.Rectangle
$Rectangle.Margin = $Margin
$Rectangle.Width = $Size.Split(",")[0]
$Rectangle.Height = $Size.Split(",")[1]
if($VisualBrush){$Rectangle.Fill = $VisualBrush}
return $Rectangle
}