0
爲了使用ItemsControl綁定圖像源,我們需要使用哪種類型的列表。我有這樣一個ItemsControl:圖像類型ItemsControl上的錯誤
<ItemsControl x:Name="championPicControl" Margin="10,0,516,63">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Height="100" Width="100"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
而且它還有我一個錯誤,當我做的:
List<BitmapImage> list = new List<BitmapImage>();
foreach(var i in summsList)
{
BitmapImage champ = new BitmapImage();
champ.BeginInit();
champ.UriSource = new Uri("Resources/championsSquare/" + i.championName + "_Square_0.png", UriKind.Relative);
champ.EndInit();
list.Add(champ);
}
championPicControl.ItemsSource = list;
我應該爲了得到它的工作怎麼辦列表的類型和什麼?
你看到了什麼錯誤? – FishStix
我在你的代碼中看到2個潛在的問題: 對於嵌入式資源,最好使用UriKind.Absolute'pack:// application:,,,/[YourAssemblyName]; component/Resources/{Y ourImageName} .' 需要使用ObservableCollection而不是List – Anton