我正在开发Windows Phone 7,我需要将图像添加到ListBox.我想用C#代码,而不是XAML.我读到了它,但每个人都使用BitmapImage,我无法在Windows Phone 7上工作.我有XAML代码:StackPanel Margin=0,0,0,17local:Mat...
我正在开发Windows Phone 7,我需要将图像添加到ListBox.
我想用C#代码,而不是XAML.
我读到了它,但每个人都使用BitmapImage,我无法在Windows Phone 7上工作.
我有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>
和我的班级MatchDates中的C#函数:
void add_items(List<List<string>> code)
{
if (code.Count == 0)
this.Items.Add("no mathes");
else
{
foreach (List<string> temp1 in code)
{
foreach (string temp2 in temp1)
{
this.Items.Add(temp2);
}
this.Items.Add("---------------------------------");
}
}
}
如何在add_items函数中添加图像?
这段代码:
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?
解决方法:
我使用的方法之一:
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#:
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;
为了检索文章,我使用WCF服务.
沃梦达教程
本文标题为:将图像添加到ListBox(c#,windows phone 7)
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
猜你喜欢
- Unity3D实现渐变颜色效果 2023-01-16
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- Unity Shader实现模糊效果 2023-04-27
- 如何使用C# 捕获进程输出 2023-03-10
- user32.dll 函数说明小结 2022-12-26
- .NET CORE DI 依赖注入 2023-09-27
- c# 模拟线性回归的示例 2023-03-14
- Oracle中for循环的使用方法 2023-07-04