Check the output window in Visual Studio for runtime data binding errors.
There are two problems with the code you've shown:
1) You've declared the
ImgSource
variable as either a local variable, or a field. WPF binding only works with properties.
2) Since you're binding to something defined in your code-behind, you need to set the
DataContext
to the class instance which contains the property, either on the image itself, or somewhere higher up in the logical tree. The usual approach is to do that in the constructor.
Public Partial Class Window1 : Window
Public Sub New()
InitializeComponent()
DataContext = Me
Dim base64string As String = ...
Dim bi As New BitmapImage()
bi.BeginInit()
bi.StreamSource = New MemoryStream(Convert.FromBase64String(base64String))
bi.EndInit()
Dim img As New Image()
img.Source = bi
ImgSource = img
End Sub
Public ReadOnly Property ImgSource As Image
End Class