I have started a little image browser with wpf.
An ObservableCollection is binded to a Listview
This ObservableCollection (of a personalized class) have 2 DependencyProperty (PathProperty as Uri, and ImgProperty as Bitmapimage).
I create a thread who browse the ObservableCollection and, for each item, create a bitmapImage with PathProperty , and set the ImgProperty with this bitmapimage.
For Each itm As itemW In instance
Dim img As New BitmapImage
img.BeginInit()
img.CacheOption = BitmapCacheOption.OnLoad
img.CreateOptions = BitmapCreateOptions.IgnoreColorProfile
img.DecodePixelWidth = 120
img.UriSource = itm.Chemin 'ERROR inter thread
img.EndInit()
itm.Image = img 'ERROR inter thread
Next
But that don't work, Inter thread operation error.
I have finded a solution , to use DispatcherOperationCallback but that don't work very well.
For the PathProterty get :
...
Get
return me.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, New Windows.Threading.DispatcherOperationCallback(AddressOf test), PathProperty)
End Get
Function testtt1(ByVal value As Object) As Object
Return GetValue(value)
End Function
That's work , i can get the PathProperty in the thread.
But with the ImgProperty, that don't work !
In the thread if i set the created bitmapimage i have an inter thread error
The ImgPropertySet :
Set
Me.Dispatcher.BeginInvoke(Windows.Threading.DispatcherPriority.Background, New Windows.Threading.DispatcherOperationCallback(AddressOf test2), value)
End Set
Function test2(ByVal value As Object) As Object
SetValue(ImgProperty, value)
Return Nothing
End Function
Could you Help Me
Thanks for you help
Excuse me i'm french and i don't speak english very well.