I'm trying to put a data grid in a WPF. Simple enough in Powershell.. But when i run the code in Powershell 2.0, it can't find gives me errors.
Sample code:
Add-Type -AssemblyName PresentationFramework
$xaml = [xml] @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="My window" Height="300" Width="300">
<DockPanel>
<Button x:Name="okButton" Content="OK" DockPanel.Dock="Bottom" />
<DataGrid x:Name="DataGrid" DockPanel.Dock="Top"/>
</DockPanel>
</Window>
"@
$reader = New-Object System.Xml.XmlNodeReader $xaml
$form = [Windows.Markup.XamlReader]::Load($reader)
$okButton = $form.FindName("okButton")
$okButton.add_Click({ $form.Close() })
$form.WindowStartupLocation = "CenterScreen"
$form.ShowDialog();
If you remove this line, everything work fine:
<DataGrid x:Name="DataGrid" DockPanel.Dock="Top"/>
Anyone has any suggestions?
Error i get in Powershell 2.0:
Exception calling "Load" with "1" argument(s): "The tag 'DataGrid' does not exist in XML namespace 'http://schemas.microsoft.com/winfx /2006/xaml/presentation'. Line '0' Position '0'." At line:15 char:42 + $form = [Windows.Markup.XamlReader]::Load <<<< ($reader) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException