2017-11-10 85 views
1

我正在尝试使用WPF进行简单的instagram提要显示。我有一个ListView,它绑定到从Instagram API检索的图像url的ObservableCollection。出于某种原因,我只能加载前10个左右(尽管我试图绑定更多)。如果我尝试加载较低分辨率的图像,那么它似乎可以正常工作。但我不是在谈论大量的图像(可能每个大约10万)。从web上加载大量图像时遇到问题

下面是一些示例代码,其中包含来自instagram的硬编码图像列表。对我来说,这只会加载前10个,然后会丢失数字11,然后加载数字12.我不知道为什么。

XAML:

<ListView x:Name="List" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.CanContentScroll="False"> 
    <ListView.ItemsPanel> 
     <ItemsPanelTemplate> 
      <WrapPanel /> 
     </ItemsPanelTemplate> 
    </ListView.ItemsPanel> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <Grid Width="250" Height="250" Background="Orange"> 
       <Image Margin="3" Source="{Binding}" Stretch="Uniform" VerticalAlignment="Center" /> 
      </Grid> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

后面的代码:

List<string> content = new List<string>() 
{ 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23498621_155088151891201_5838888733310451712_n.jpg",  
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/e15/23421369_1935881716650536_2751759012239245312_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23498900_2424691114423634_1760461413358239744_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23498900_2424691114423634_1760461413358239744_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23347618_263128534210376_920911369891479552_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421069_1500830839998934_8413516091602501632_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23417348_742804169243503_6556496499100876800_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23347902_2017564028488677_2880579113104441344_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421331_334537296949861_4296430067371737088_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421331_334537296949861_4296430067371737088_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23416590_1928818560779337_7080637368553701376_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/sh0.08/e35/p640x640/23421758_491705774540588_6178820534202007552_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421099_1728264697245367_6448825186568372224_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23416994_133163334113394_1499431022142423040_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421239_1483718185060885_8134914164545028096_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23280089_1942832749376286_3936575794389712896_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23347674_2006888666245374_7306582919252803584_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23347388_119626992143009_7585283007787827200_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421865_90030116_1326331715420946432_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23421253_148762415872849_1558483017121398784_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/sh0.08/e35/p640x640/23507217_1953269574998281_6711372701967056896_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/sh0.08/e35/p640x640/23507217_1953269574998281_6711372701967056896_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23498098_2009691429314434_8349013357923139584_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/e15/23347679_315062128974030_5091325576380153856_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/sh0.08/e35/p640x640/23421083_1777350415899180_3004366087824343040_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/sh0.08/e35/p640x640/23421083_1777350415899180_3004366087824343040_n.jpg", 
    "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/23498903_773821689486761_9202713497564086272_n.jpg" 
}; 

List.ItemsSource = content; 
+0

似乎ObservableCollection完全是多余的。你也可以编写'List.ItemsSource = content;'如果因为某种原因你仍然需要它,像'oDataCollection = new ObservableCollection (content);' – Clemens

+0

这样初始化它是的,你是对的,我没有在示例代码中显示。现在编辑代码以删除可观察的集合。 – user2424495

回答

1

您正在运行到最大连接限制在同一主机的应用程序。

在你的app.config文件,你可以添加以下下面的配置:

<system.net> 
    <connectionManagement> 
    <add address="*" maxconnection="1000" /> 
    </connectionManagement> 
</system.net> 

你可以阅读更多关于这个here。很显然,您应该根据您的应用程序实际需要来定制您的条目。

+0

非常感谢! – user2424495