0

我创建了一个动态数据透视表,其中数据通过一个列表绑定,其中数据随机更改几乎范围在列表中的 100-150 个条目之间。一切顺利,数据被添加到列表中,但是当数据被绑定时,应用程序意外终止并显示内存不足异常

我的代码有点像这个 xaml

<Controls:Pivot x:Name="pvtDeals" Background="Gray" ItemsSource="{Binding CityItemList}" Grid.Row="1">
   <Controls:Pivot.ItemTemplate>
       <DataTemplate>
           <Grid >
               <Grid.RowDefinitions>
                   <RowDefinition Height="200"/>
                   <RowDefinition Height="Auto"/>
                   <RowDefinition Height="*"/>
               </Grid.RowDefinitions>
               <Image x:Name="imgDeal" Tag="0" Source="{Binding ImageLink}" Stretch="Uniform" HorizontalAlignment="Stretch"  />
               <TextBlock Foreground="Red" Text="{Binding Title}" Grid.Row="1" TextWrapping="Wrap"/>
               <ScrollViewer Grid.Row="2">
                   <TextBlock Foreground="Black" Text="{Binding Description}" TextWrapping="Wrap" Grid.Row="2"/>
               </ScrollViewer>
           </Grid>
       </DataTemplate>
   </Controls:Pivot.ItemTemplate>
</Controls:Pivot>

cs代码

var xml = XDocument.Parse(e.Result); // from XML string, e.g.


// SaveDealInfoToIsolatedStorage(e.Result);

System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("<[^>]*>");

        var Channel = xml.Root.Elements("channel").ToList();
        var items = Channel[0].Elements("item").ToList();
        App.MainViewModel.CityItemList.Clear();

        foreach (var item in items)
        {
            App.MainViewModel.CityItemList.Add(new Model.CityItems
                {
                    Title = item.Element("title").Value,
                    Description = rx.Replace(item.Element("description").Value.Replace("\"", string.Empty), string.Empty),
                    ImageLink = item.Element("imageURL").Value,//image,
                    WebLink = item.Element("link").Value
                });

            System.Diagnostics.Debug.WriteLine(App.MainViewModel.CityItemList.Count.ToString());
        }
4

0 回答 0