1

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" ?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Bahaïka
  • 699
  • 1
  • 11
  • 36

1 Answers1

1

It looks like you are not implementing the INotifyPropertyChanged Interface. Take a look at this page on MSDN. I'm not sure if this is also a problem but try setting the height and width of the image.

H.B.
  • 166,899
  • 29
  • 327
  • 400
evanb
  • 3,061
  • 20
  • 32
  • The size should not matter as the Image will expand in at least one direction when using a StackPanel and resizing keeps the aspect ratio, hence it should take some space. – H.B. Aug 31 '11 at 21:24
  • Try calling your NotifyPropertyChanged handler after you set the ElementIcon.StreamSource. The NotifyPropertyChanged is usually only called when you set the ElementIcon and since you are reusing the BitmapImage, it is only called once on construction. – evanb Aug 31 '11 at 21:48
  • Look at my first post, I edited my class to add what you said but it still did'nt work – Bahaïka Aug 31 '11 at 22:02