我对WPF有一个奇怪的问题,我在运行时从磁盘加载图像并将其添加到Canvas容器中。我的图像大小超过20MB。我需要在一个窗口中显示20到30张图像,并且我想完全清晰地显示图像。我的问题是某些图像没有显示。在我的代码下面
for (var i = 0; i < Count; i++)
{
BitmapImage bmp=new BitmapImage(new Uri(ImagePath, UriKind.RelativeOrAbsolute));
Image imageControl = new Image();
imageControl.Source = bmp;
MyCanvas.Children.Add(imageControl);
}
答案 0 :(得分:1)
<ItemsControl x:Name="imageLists">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Width="500" Margin="15"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
像这样设置ItemsControl的ItemsSource:
imageLists.ItemsSource = Directory.EnumerateFiles(FOLDERPATH, "*.*");