Search code examples
imagewindows-phone-8data-bindingwindows-phone-8.1bitmapimage

How to bind image with BitmapImage in windows phone 8?


<Image Height="100" Width="100" Margin="12,0,9,0">   
    <Image.Source>    
        <BitmapImage UriSource="{Binding ImgURL}" CreateOptions="BackgroundCreation"/>   
    </Image.Source>
</Image>

I don't know how to bind image with control BitmapImage.

Help me!


Solution

  • In .cs file you set source as below

    1.) Give name to your XAML image control like x:Name="img"

    2.) img.Source = new BitmapImage(new Uri(URL, UriKind.RelativeOrAbsolute))

    URL = which link you are getting in ImgURL

    I hope this will helpful to you.

    Edit

    ImageSource imgSource = null;
    BitmapImage bm = new BitmapImage(new Uri(URL, UriKind.RelativeOrAbsolute));
    imgSource = bm;
    img.Source = imgSource;