-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConvertTo-GridLength.ps1
44 lines (43 loc) · 1.45 KB
/
ConvertTo-GridLength.ps1
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
function ConvertTo-GridLength
{
<#
.Synopsis
Turns $legnth into Windows.GirdLength objects
.Description
Turns the length parameter into GridLength objects.
.Parameter length
If the Length is just one integer, than that number of grid lengths will be created.
If the Length is a list of strings and integers, then individual rows will be created
If the string is 'Auto', the GridLength will be AutoSized
If the string is a number followed by *, the GridLength will be a ratio of the available space
If the string is a number, then the GridLength will be a specific number of pixels
.Example
ConvertTo-GridLength 5
.Example
ConvertTo-GridLength 'Auto','1*', 'Auto'
#>
param(
$length
)
if ($length -as [uint32]) {
foreach ($n in (1..$length)) {
New-Object Windows.GridLength 1,Star
}
} else {
foreach ($l in $length) {
switch ($l) {
Auto {
New-Object Windows.GridLength 1, Auto
}
{$_ -as [Double]} {
New-Object Windows.GridLength $_, Pixel
}
{"$_".EndsWith('*')} {
$ratio = "$_".Split("*")[0]
if (-not $ratio) { $ratio = 1 }
New-Object Windows.GridLength $ratio, Star
}
}
}
}
}