Private/_CreateWindow.ps1
function _CreateWindow { [CmdletBinding()] param ( [Parameter()] # [ValidateScript( { Test-Path $_ } )] [string]$xamlFile, [string]$WindowName ) begin { try { $WindowName = $xamlFile.split('\')[-1].split('.')[0] } catch { throw } } process { # TODO testing line, will need updated when published. # $xamlFile = 'C:\Users\lkranz\Desktop\ADLookups-v2\ADLookups.xaml' # $xamlFile = "$ModuleRoot\Assets\ADLookups.xaml" #create window try { $inputXML = Get-Content $xamlFile -Raw $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace 'x:N', 'N' -replace '^<Win.*', '<Window' [XML]$XAML = $inputXML } catch { throw } #Read XAML try { $reader = (New-Object System.Xml.XmlNodeReader $xaml) Write-Host '$Reader' $reader } catch { throw } try { # TODO i think my issue is here. i have the problem of not knowing the how to do the following lines. the variable is created, but the value isn't added. $Form = [Windows.Markup.XamlReader]::Load( $reader ) # Set-Variable -Name $WindowName -Scope Global -Value ([Windows.Markup.XamlReader]::Load( $reader )) # Write-Output '$WindowName' # $WindowName # Get-Variable -Name $WindowName | select -ExpandProperty value # $WindowNameVariable = Get-Variable -Name "$WindowName" } catch { throw } return $Form $xaml.SelectNodes('//*[@Name]') | ForEach-Object { try { Set-Variable -Name "$($WindowName)_$($_.Name)" -Value $Form.FindName($_.Name) -Scope Global -ErrorAction Stop } catch { throw } } } end { } } |