0
你好,我有問題在列表視圖中顯示圖片。我有一個網址的數組,我必須下載圖片,但爲了測試目的,我嘗試從我的本地硬盤驅動器填充每行相同的圖片。我可以綁定數據,但到目前爲止,我可以打印到圖片collumn的唯一的事情就是對象的名稱,但不是圖片本身(DisplayData.Image)這是我的XAML和C#代碼:無法在列表視圖中顯示圖片
XAML
<Window x:Class="TestIT.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestIT"
Title="MainWindow" Height="510.9" Width="723">
<Window.Resources>
<local:InterfaceBinding x:Key="adjust" />
</Window.Resources>
<Grid>
<Grid HorizontalAlignment="Stretch" Height="100" VerticalAlignment="Stretch" Width="517" Margin="98,10,100,370" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
</Grid.RowDefinitions>
<Label x:Name="labelNewsTop" Content="Top News" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="0" MouseLeftButtonUp="labelNewsTop_MouseLeftButtonUp" />
<Label x:Name="labelNewsBusiness" Content="Business" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="1" />
<Label x:Name="labelNewsTechnology" Content="Technology" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="2" />
<Label x:Name="labelNewsEntertainment" Content="Entertainment" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="3" />
<Label x:Name="labelNewsScience" Content="Sport" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="4" />
<Label x:Name="labelNewsHealth" Content="Health" Grid.Row="0" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Grid.Column="5" />
<Image x:Name="iamgetest" Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="100" Margin="24,68,0,-68" VerticalAlignment="Top" Width="100" Grid.Column="4"/>
</Grid>
<ListView x:Name="testView" HorizontalAlignment="Left" Height="304" Margin="0,105,0,0" VerticalAlignment="Top" Width="715">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}"/>
<GridViewColumn Header="Lele" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Image Height="50" Width="50" Stretch="Fill" Source="{Binding Path=Image}"></Image>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
C#
GNews gnews = new GNews();
List<NewsModel> bla = gnews.getTopNews();
for (int i = 0; i < bla.Count - 1; i++)
{
DisplayData data = new DisplayData();
data.Name = bla[i].title;
data.Value = bla[i].url;
ImageSource mySource = new BitmapImage(new Uri("D:\\New folder\\New folder\\other\\Wall\\010.jpg"));
data.Image = new Image();
data.Image.Source = mySource;
this.testView.Items.Add(data);
}
}
}
public class DisplayData
{
public string Name { get; set; }
public string Value { get; set; }
public Image Image { get; set; }
}
哦TY完美的作品...什麼是這個在線託管,因爲我需要一點時間來下載他們所有的照片組合的最佳方式。我應該把所有東西放在不同的線程上嗎?並再次感謝answere這是真的很快:) – Proxy 2015-04-01 21:50:46
如果你不需要明確地下載它們,你可以把你的URI作爲一個http資源 – 2015-04-01 21:54:09
我不明白你在說什麼知道...你的意思是我應該使用http請求或?下載它們 – Proxy 2015-04-01 22:00:24