简体   繁体   English

C#Windows Phone:是否可以用图像填充LongListSelector?

[英]C# Windows Phone: Is it possible to fill LongListSelector with images?

I fill a LongListSelector with names of products and i would like to put images of products too in my LongListSelector. 我用产品名称填充LongListSelector,我也想在我的LongListSelector中放置产品图像。 I get my datas from my webserver using webclient method. 我使用webclient方法从网络服务器获取数据。 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. 但是我不知道如何在长列表选择器上显示图像。

You should keep the URL of the image as an attribute to your product, not the image source itself. 您应该将图像的URL保留为产品的属性,而不是图像源本身。 So you can have something like 所以你可以像

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

And in xaml: 在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. 就像建议一样,通过将堆栈面板替换为网格,您已经可以为您的图像保留空间(100像素),该空间是异步下载的。 Otherwise, when the image will apear on the screen, it will move all the other content. 否则,当图像出现在屏幕上时,它将移动所有其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM