-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShow-XAML
More file actions
38 lines (33 loc) · 1.03 KB
/
Show-XAML
File metadata and controls
38 lines (33 loc) · 1.03 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
function Show-Xaml
{
[cmdletbinding()]
param(
[parameter(Mandatory = $true, ValueFromPipeLineByPropertyName = $true, HelpMessage = 'The path to the XAML file to run')]
[ValidateScript({Test-Path -path $_})]
[string]$FilePath
)
Add-Type -AssemblyName PresentationFramework -ErrorAction SilentlyContinue
Add-Type -AssemblyName PresentationCore -ErrorAction SilentlyContinue
Add-Type -AssemblyName WindowsBase -ErrorAction SilentlyContinue
$xaml = New-Object -TypeName XML
$xaml.Load($FilePath)
$xaml.Window.RemoveAttribute('x:Class')
$xaml.Window.RemoveAttribute('mc:Ignorable')
$reader = [System.Xml.XmlNodeReader]::new($xaml)
$Window = [Windows.Markup.XAMLReader]::Load($reader)
<#
$nodes = $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
foreach ($node in $nodes)
{
if (Test-Path Variable:\$($node.name))
{
Write-Verbose -Message "Variable $($node.name) exists"
}
else
{
New-Variable -Name $node.Name -Value ($Window.FindName($node.name))
}
}
#>
$null = $Window.ShowDialog()
}