torr
0
Q:

powershell read xaml file

# =========================================================================================
# Read XAML Window
# =========================================================================================
$currentDir = Split-Path $myInvocation.MyCommand.Path
#$mainWindow = [IO.File]::ReadAllText($currentDir + "\MainWindow.xaml") 
$mainWindow = [IO.File]::ReadAllText($currentDir + "\..\wpf\ImageShrinker\MainWindow.xaml")

# XAML Code kann zwischen @" und "@ ersetzt werden:
[xml]$XAML = $mainWindow -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window' #-replace wird benötigt, wenn XAML aus Visual Studio kopiert wird.
# XAML laden
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
try{
   $window=[Windows.Markup.XamlReader]::Load( (New-Object System.Xml.XmlNodeReader $XAML) )
} catch {
   Write-Host "Windows.Markup.XamlReader konnte nicht geladen werden. Mögliche Ursache: ungültige Syntax oder fehlendes .net"
}
0

New to Communities?

Join the community