0

I fill a LongListSelector with names of products and i would like to put images of products too in my LongListSelector. I get my datas from my webserver using webclient method. To get an image i only know i should use something like this:

pic.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("http://srvname.com/images/greenpasta.jpg"));

But i don't know how to show images on long list selector.

Kara
  • 6,115
  • 16
  • 50
  • 57
  • What does your xaml look like? You probably need to use a `ValueCoverter` I recommend you look at this similar post to get you started: http://stackoverflow.com/questions/20586/image-urisource-and-data-binding – Nate May 18 '14 at 16:35
  • (sorry for the code in comment i have a new stack account i can t post a answer)Thanks to help me. My xaml looks like this: > > > > > > > – user3627729 May 18 '14 at 16:45
  • @user3627729 You can edit your question to add more code or infomation. – Kara May 21 '14 at 00:25

1 Answers1

0

You should keep the URL of the image as an attribute to your product, not the image source itself. So you can have something like

    myProduct.uri = new Uri("http://srvname.com/images/greenpasta.jpg")

And in xaml:

    <DataTemplate>
    <Grid>
      <Grid.ColumnDefinition>
      <ColumnDefinition Witdh="100" \>
      <ColumnDefinition Witdh="Auto" \>
      <ColumnDefinition Witdh="*" \>
      </Grid.ColumnDefinition>
      <Image Source="{Binding uri}" Height="100" Stretch="Fill"/> >           
      <TextBlock Text="{Binding Name}" /> >
    </Grid>
    </DataTemplate>

Just as a suggestion, by replacing the stackpanel to a grid, you can already reserve space for your image (100 pixels), which is downloaded async. Otherwise, when the image will apear on the screen, it will move all the other content.

Dacian Mujdar
  • 585
  • 2
  • 17