Changing Image_Name.Source


  • I have a image toolbox defined in XAML call "im" ..how can i change it's source in C#?

    If i use im.Source="pathofimage" , it shows error, how can i do it?


    • Edited by me_Techguy Monday, May 19, 2014 5:26 PM
    Monday, May 19, 2014 5:25 PM


  • Hi,

    If you create an Image object using code, Image.Source requires  a BitmapImage or BitmapSource (not a URI) in code. If your source is content in your app, use the BitmapImage constructor that takes a URI. The Windows Runtime enforces that a URI must be absolute, you can't use relative URIs in Windows Runtime code. Please refer to the codes below:


    <Image HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Name="image"/>


     BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(image.BaseUri,"Assets/Logo.scale-100.png");
                image.Source = bitmapImage;
    Best Wishes!

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, May 20, 2014 1:31 AM