SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Windows Phone Application Development Tutorials, Articles and Resources for Mobile App Programmers

Set Image Source Property in Windows Phone App Project

If you are using Image control on your Windows Phone 8 app pages, you can set Image.Source property using ImageSourceConverter class and its ConvertFromString method. In this Visual Studio 2012 Windows Phone app programming tutorial, I'll show how to set source of image control using VB.NET code where the image is placed on MainPage.xaml at design time.

Use ImageSourceConverter in Windows Phone 8 App Code Behind

Assume that I have an image control named "image" placed on page .xaml design code as follows.

<Image x:Name="image" HorizontalAlignment="Center" Margin="100,0,0,0" VerticalAlignment="Bottom" Width="100" />

Now let's set .XAML Image Source value using VB.NET. In VB.NET code behind of this Windows Phone 8 app page, use following ImageSourceConverter class and ConvertFromString method code to set Image.Source property of this image control to a relative URL pointing to an image within the app project assets.

Dim imagesource As String = "/assets/images/samplephoto.png"

Dim imagesourceconverter As New ImageSourceConverter()
image.Source = imagesourceconverter.ConvertFromString(imagesource)

Here is a sample of the output where a dummy image is displayed at the bottom of the Windows Phone app page. Using Visual Studio 2012 WP8 development IDE, we have set image source property of the XAML Image control placed on page at design time. When we run the app the image we want is displayed.

set source of image control programatically ImageSourceConverter and ConvertFromString
Set source of an Image control programatically using ImageSourceConverter class and ConvertFromString method

Windows 10 Games

Microsoft Games on Windows 8 and Windows 10

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.