OutOfMemoryException unhandled
本文关键字:unhandled OutOfMemoryException | 更新日期: 2023-09-27 18:19:38
"Windows Phone Emulator-WVGA 512 MB"和我的设备出现以下异常。当使用"Windows Phone Emulator-WVGA"时,我不会遇到这个问题。
这是我的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);
}
您使用的RAM太多。你需要想办法去掉全景图中的几个项目,或者制定一个方案,只在相关内容出现时加载,例如,只在图像显示在屏幕上之前加载图像。
因此,与其一次加载所有图像,不如在用户向左或向右滑动时加载它们。或者决定每个"页面"的数量,一次只加载那么多。