将图像添加到列表框(c#,windows phone 7)

将图像添加到列表框(c#,windows phone 7),c#,windows-phone-7,C#,Windows Phone 7,我正在开发WindowsPhone7,我需要将图像添加到列表框 我想用C代码,而不是XAML 我读过,但每个人都使用BitmapImage,我无法在WindowsPhone7上使用它 我有XAML代码: <StackPanel Margin="0,0,0,17"> <local:MatchDates Adress="http://soccernet.espn.go.com/results/_/league/esp.1/spanish-la-liga?cc=57393"

我正在开发WindowsPhone7,我需要将图像添加到列表框

我想用C代码,而不是XAML

我读过,但每个人都使用BitmapImage,我无法在WindowsPhone7上使用它

我有XAML代码:

<StackPanel Margin="0,0,0,17">
    <local:MatchDates Adress="http://soccernet.espn.go.com/results/_/league/esp.1/spanish-la-liga?cc=57393" />
</StackPanel>

仅显示空白,如何将图像添加到列表框?

支持位图图像。您必须将BitmapImage声明为ImageSource。

我使用的方法之一:

XAML:

<ListBox Name="lstView" ItemsSource="{Binding}">
   <ListBox.ItemTemplate>
      <DataTemplate>
          <StackPanel Orientation="Horizontal">
             <Image Source="{Binding ImagePath}"></Image>
             <TextBlock Text="{Binding Name}"></TextBlock>
        </StackPanel>
      </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

C#:

公共类文章
{
公共字符串名称{get;set;}
公共字符串ImagePath{get;set;}
}
Article Article 1=新文章(){Name=“name1”,ImagePath=“图像1的路径”};
Article article2=新文章(){Name=“name2”,ImagePath=“图像的路径2”};
var articles=新列表();
增加(第1条);
增加(第2条);
lstView.DataContext=文章;

为了检索文章,我使用WCF服务。

您能给我一个代码示例吗?这是我的第一个项目:)我在一个应用程序中使用了这个项目:uriimageuri=newuri(“herecomestheUri”,UriKind.RelativeOrAbsolute);新的BitmapImage(){UriSource=imageUri};ImageSource SrcImage=imageUri;这是一个非常简单的例子,但我的答案后面的例子也是一个很好的例子;BitmapImage位图=新的BitmapImage(uri);图像img=新图像();img.高度=30;img.宽度=30;img.Source=位图;此.Items.Add(img)?我想这个.Items.Add(img)是错误的
    Uri uri = new Uri("/eng.png", UriKind.Relative);
    BitmapImage bitmap = new BitmapImage(uri);
    Image img = new Image();
    img.Height = 30;
    img.Width = 30;
    img.Source = bitmap;
    this.Items.Add(img);
    this.Items.Add(temp2);
<ListBox Name="lstView" ItemsSource="{Binding}">
   <ListBox.ItemTemplate>
      <DataTemplate>
          <StackPanel Orientation="Horizontal">
             <Image Source="{Binding ImagePath}"></Image>
             <TextBlock Text="{Binding Name}"></TextBlock>
        </StackPanel>
      </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>
public class Article
{
    public string Name { get; set; }

    public string ImagePath { get; set; }
}


 Article article1 = new Article() { Name = "name1", ImagePath = "path of image 1" };
 Article article2 = new Article() { Name = "name2", ImagePath = "path of image 2" };

 var articles = new List<Article>();
 articles.Add(article1);
 articles.Add(article2);

 lstView.DataContext = articles;