I am adding object directly to a ListBox, and inside this class, I've got a BitmapImage object. I'm using an ItemTemplate :
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<Image Source="{Binding Path=ElementIcon}"></Image>
<TextBlock Text="{Binding Path=ElementName}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
And I directly add object of this class :
Public Class ExplorerClass
Implements INotifyPropertyChanged
Public Property ElementType As String = Nothing
Public Property ElementName As String = Nothing
Public Property ElementContainer As String = Nothing
Public Property ElementIcon As New BitmapImage
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Public Sub New(ByVal WantedElementContainer As String, ByVal WantedElementName As String, ByVal WantedElementType As String)
ElementType = WantedElementType
ElementName = WantedElementName
ElementContainer = WantedElementContainer
Dim str As New MemoryStream
Dim IWorking As Icon = showIcon(ElementName.Substring(ElementName.LastIndexOf(".")))
IWorking.ToBitmap.Save(str, System.Drawing.Imaging.ImageFormat.Png)
ElementIcon.BeginInit()
ElementIcon.StreamSource = str
ElementIcon.EndInit()
NotifyPropertyChanged("ElementIcon")
End Sub
End Class
But, there is no pictures showed; So, my question is : "How can I bind the BitmapImage" ?