Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 14973

How to Update and Remove the .xaml Image.Source Property using Visual Basic code

$
0
0
Microsoft Visual Studio Community 2019 Version 16.8.4
VB.NET WPF
How to Update and Remove the .xaml Image.Source Property using
Visual Basic code?
<Image x:Name="ImgPicture"
Grid.Column="0"
Margin="30,47,0,0"
Source="C:\CPG\Picture\cat.jpg"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Height="43"
Width="50"
Visibility="Visible"
RenderTransformOrigin="0.78,1.38">
</Image>
The Image Source Property must be included in the above .xaml
I can not leave it blank or remove it without a
"An attribute name is missing" error. I could change the
Visibility="Hidden" to accomplish "Removal."
Picture Box is not available, since I am using WPF .xaml

Behind VB code...
ImgPicture.Source = "C:\CPG\Picture\cat.jpg"
gives a "Value of type 'String' cannot be converted to
'ImageSource' message. It seems it has be a BitmapImage...
Dim myImage As New Image
Dim myBitmap As New BitmapImage

myBitmap.BeginInit()
myBitmap.UriSource = New Uri("C:\CPG\Picture\cat.jpg")
myBitmap.EndInit()

myImage.Source = myBitmap
* ImgPicture.Source = myImage.Source
* The above VB code gives a "Value of type 'String' cannot be converted
to 'ImageSource' message.

If you have any suggestions on how I can Update/Remove the
ImgPicture.Source Property using behind VB code , please let me know.

Thanks in advance.

Viewing all articles
Browse latest Browse all 14973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>