Chetan Zope
Chetan Zope

Reputation: 55

Bind ImageSource in Windows Phone

I am Using LazyListBox as given below.There is an Image in Data Template.And I am not able to Bind the ImageUrl.How can i Bind ImageSource.

  <lazy:LazyListBox x:Name="d" ItemSource={Binding ProductImageLIst}>
            <lazy:LazyListBox.LoadedItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Product_Id}" Foreground="Black"></TextBlock>
                        <Image x:Name="img" Source="{Binding Path=ImageUrl}"></Image>
                    </StackPanel>
                </DataTemplate>
            </lazy:LazyListBox.LoadedItemTemplate>
        </lazy:LazyListBox>

And my ProductImageList Class is Shown Below

 public  class ProductImageList
    {

        public string  ImageId { get; set; }
        public string ImageUrl{ get; set; }
        public string Product_Id { get; set; }
        public string  Category_id { get; set; }
        public ProductImageList()
        {

        }
        public ProductImageList(string imageid, string imageurl, string productid,string catid)
        {
            this.ImageId = imageid;
            this.ImageUrl = imageurl;
            this.Product_Id = productid;
            this.Category_id = catid;

        }
    }

Upvotes: 0

Views: 310

Answers (1)

Jaihind
Jaihind

Reputation: 2778

Use BitmapImage to bind source of image in LazyListBox control. Here is the solution. If your 'ImageUrl' is a http url you should first download image from this url and create BitmapImage by downloaded image stream, and if your imageUrl is a relative url create BitmapImage as below.

<lazy:LazyListBox x:Name="d" ItemSource={Binding ProductImageLIst}>
            <lazy:LazyListBox.LoadedItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Product_Id}" Foreground="Black"></TextBlock>
                        <Image x:Name="img" Source="{Binding Path=ImageSource}"></Image>
                    </StackPanel>
                </DataTemplate>
            </lazy:LazyListBox.LoadedItemTemplate>
        </lazy:LazyListBox>

public  class ProductImageList
    {

        public string  ImageId { get; set; }
        public string ImageUrl{ get; set; }
        public string Product_Id { get; set; }
        public string  Category_id { get; set; }
        public BitmapImage ImageSource{get;set;}
        public ProductImageList()
        {

        }
        public ProductImageList(string imageid, string imageurl, string productid,string catid)
        {
            this.ImageId = imageid;
            this.ImageUrl = imageurl;
            this.Product_Id = productid;
            this.Category_id = catid;
            this.ImageSource = new BitmapImage(new Uri(imageurl, UriKind.RelativeOrAbsolute));

        }
    }

Upvotes: 2

Related Questions