I often see a lot of unnecessary code in WPF demos in PowerShell, so I want to share the most barebone version that still works correctly.
You don’t need to use New-Object System.Xml.XmlNodeReader $xaml, and you don’t need [Windows.Markup.XamlReader]::Load($reader). Just use Parse.
You also don’t need the x and d namespaces (most of the time) so you can remove them as well.
Just make sure that the $xaml variable has type [string], and you can get a working app in just few lines of code.
Add-Type -AssemblyName PresentationFramework |