I just tested an early PowerShell WPF example from here
#requires -version 2
Add-Type -AssemblyName PresentationFramework
[xml] $xaml = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="408">
<Canvas>
<Button x:Name="button1"
Width="75"
Height="23"
Canvas.Left="118"
Canvas.Top="10"
Content="Click Here" />
</Canvas>
</Window>
"@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$target=[Windows.Markup.XamlReader]::Load($reader)
$window= $target.FindName("Window")
$control=$target.FindName("button1")
$eventMethod=$control."add_click"
$eventMethod.Invoke({$window.Title="Hello $((Get-Date).ToString('G'))"})
$target.ShowDialog() | out-null
FindName seems to return $null here. I found some posts indicating, that RegisterName is needed, but I have no idea, how to apply this here.
As far as I understand your $target is your window. Can you try :
------------- EDIT -------------
Here is the code working with
FindName
I replaceCanvas
byGrid
: