I try a simple example from
[xml]$xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window" Title="Initial Window" WindowStartupLocation = "CenterScreen"
SizeToContent = "WidthAndHeight" ShowInTaskbar = "True" Background = "lightgray">
<StackPanel >
<RadioButton x:Name="Item1" Content = 'Item1'/>
<RadioButton x:Name="Item2" Content = 'Item2'/>
<RadioButton x:Name="Item3" Content = 'Item3'/>
<TextBox />
</StackPanel>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$Window=[Windows.Markup.XamlReader]::Load( $reader )
$xaml.SelectNodes(“//[@[contains(translate(name(.),‘n’,‘N’),‘Name’)]]”) | ForEach
{
Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)
}
$Window.Showdialog() | Out-Null
I get error:
[ERROR] Unable to find type [Windows.Markup.XamlReader].
[ERROR] At line:17 char:9
[ERROR] + $Window=[Windows.Markup.XamlReader]::Load( $reader )
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : InvalidOperation: (Windows.Markup.XamlReader:Typ
[ERROR] eName) , RuntimeException
[ERROR] + FullyQualifiedErrorId : TypeNotFound
[ERROR]
cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:
Process: Name Bill
[ERROR] ForEach-Object : Cannot bind parameter ‘Process’. Cannot convert the "Name
[ERROR] Bill" value of type “System.String” to type
[ERROR] “System.Management.Automation.ScriptBlock”.
[ERROR] At line:20 char:77
[ERROR] + … des(“//[@[contains(translate(name(.),‘n’,‘N’),‘Name’)]]”) | ForEach
[ERROR] + ~~~~~~~
[ERROR] + CategoryInfo : InvalidArgument: ( [ForEach-Object], Parameter
[ERROR] BindingException
[ERROR] + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerSh
[ERROR] ell.Commands.ForEachObjectCommand
[ERROR]
Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)
[ERROR] You cannot call a method on a null-valued expression.
[ERROR] At line:25 char:1
[ERROR] + $Window.Showdialog() | Out-Null
[ERROR] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] + CategoryInfo : InvalidOperation: ( , RuntimeException
[ERROR] + FullyQualifiedErrorId : InvokeMethodOnNull
[ERROR]
Please advise as to what went wrong.
Since the example is older than vs2019, that shouldn’t be the issue.
I have PowerShell extensions installed.