2014-08-28 61 views
0

我对“Windows Phone模拟器 - WVGA 512 MB”和我的设备有以下例外。在使用“Windows Phone Emulator - WVGA”时,我不会遇到这个问题。OutOfMemoryException未处理

这是我的XAML

<phone:Panorama Name="pano" > 


    </phone:Panorama> 

这是我的代码背后

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     base.OnNavigatedTo(e); 

     if (e.NavigationMode != NavigationMode.Back) 
     { 

      type = NavigationContext.QueryString["type"]; 
      ReadFromXml(type); 
     } 
    } 

    private void ReadFromXml(string type) 
    { 
     XDocument xml=XDocument.Load(@"data/image_saba7.xml"); 


     var query = from c in xml.Root.Descendants("post") 

        select c.Element("image").Value; 
     foreach (var name in query) 
     { 


       createPanoramItem("", name); 

     } 
    } 


    private void createPanoramItem(string tit, string imgurl) 
    { 
     BitmapImage image = new BitmapImage(
      new Uri(imgurl, UriKind.Relative) 
      ); 


     Grid g = new Grid(); 
     Image im = new Image 
     { 

      Source = image, 
      VerticalAlignment = System.Windows.VerticalAlignment.Center, 
      Margin = new Thickness(10, 290,-10, 80), 

     }; 
     img = imgurl; 
     im.Tap += im_Tap; 
     TextBlock t = new TextBlock 
     { 
      TextWrapping = TextWrapping.Wrap, 
      Margin = new Thickness(10, 296, 10, 300), 
      HorizontalAlignment = System.Windows.HorizontalAlignment.Center, 
      TextAlignment = TextAlignment.Right, 
      FontSize = 25, 
      FontWeight = System.Windows.FontWeights.SemiBold, 
      Foreground = new SolidColorBrush(new Color() 
      { 
       A = 255 /*Opacity*/, 
       R = 132 /*Red*/, 
       G = 91 /*Green*/, 
       B = 54 /*Blue*/ 
      }), 
      Text = tit 

     }; 


     g.Children.Add(t); 
     g.Children.Add(im); 

     PanoramaItem panoramaCtrlItem = new PanoramaItem(); 
     panoramaCtrlItem.Content = g; 
     // panoramaCtrlItem.Header = title; 
     pano.Items.Add(panoramaCtrlItem); 
    } 
+0

你为什么要这样做'try' /'catch'块?这是一个可怕的做法。当你删除它会发生什么? – Enigmativity 2014-08-28 07:13:00

+0

thw同样的问题,我这样做,试图解决这个问题 – 2014-08-28 07:25:13

回答

2

你使用太多RAM。您需要找出一种方法来摆脱全景中的一些项目,或者制定一种方案,通过这种方案您只需在事物相关时加载它们,例如仅在图像显示在屏幕上之前加载图像。

因此,不是一次加载图像,而是在用户向左或向右滑动时加载它们。或者根据“页面”决定一个数字,并且一次只加载一次。