I try to display a little XAML form which was created on visual studio 2019(application WPF .NET framework project).But it doesn't work I have the 2 errors:
Line |
25 | $MainForm = [Windows.Markup.XamlReader]::Load($Reader)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Load" with "1" argument(s): "Cannot set unknown member '{http://schemas.openxmlformats.org/markup-compatibility/2006}Ignorable'."
Line |
30 | $MainForm.ShowDialog() | Out-Null
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
Do you have a solution please? Here is my code on my powershell file .ps1, I have added the XAML code in my powershell file :
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
[XML]$XAML =
@'
<Window x:Class="WpfApp5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp5"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid/>
</Window>
'@
$XAML.Window.RemoveAttribute("x:Class")
$Reader = New-Object System.Xml.XmlNodeReader $XAML
$MainForm = [Windows.Markup.XamlReader]::Load($Reader)
$MainForm.ShowDialog() | Out-Null