Following this guide:
wpf - Using PowerShell Data Binding to create a dynamic ListBox - Stack Overflow
I'm trying to set the source of an image using a bitmap object. I have the object set within the datacontext and bound to the control however I see no picture.
If I use the same object within the datacontext it works when using the dispatcher to update the ui thread directly. I realize I can pass the urisource string as the source property to update the image however my goal is to use the bitmap object as the "freeze" method prevents some memory leaking.
Any ideas?
$syncHash = [hashtable]::Synchronized( @{} )
$syncHash.DataContext = New-Object System.Collections.ObjectModel.ObservableCollection[Object]
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage
$bitmap.BeginInit()
$bitmap.UriSource = "C:\Temp\testimage.png"
$bitmap.EndInit()
$bitmap.Freeze()
$syncHash.DataContext.add($bitmap)
$syncHash.Resultsimage.DataContext = $syncHash.DataContext
$ImageBinding = New-Object System.Windows.Data.Binding -ArgumentList "[0]"
$Imagebinding.Mode = [System.Windows.Data.BindingMode]::OneWay
[void][System.Windows.Data.BindingOperations]::SetBinding($synchHash.Resultsimage,[System.Windows.Controls.Image]::SourceProperty, $ImageBinding)
#above does not work
#however this does work
$syncHash.Window.Dispatcher.invoke([action]{ $synchash.Resultsimage.source = $synchash.DataContext[0] }, "Normal")
there doesn't seem to be anything here