当前位置: 动力学知识库 > 问答 > 编程问答 >

faster way to load listbox images in windows phone

问题描述:

I am developing windows phone app where I am using list box .In list box I am binding some images.Here is my code......

in code behind.....

 public MainPage()

{

InitializeComponent();

getImages();

}

public void getImages()

{

try

{

MediaLibrary mediaLibrary = new MediaLibrary();

var pictures = mediaLibrary.Pictures;

foreach (var picture in pictures)

{

BitmapImage image = new BitmapImage();

image.SetSource(picture.GetImage());//out of memory exception

img mediaImage = new img();

mediaImage.Imgs = image;

imageList.Items.Add(mediaImage);

}

}

catch (Exception ex)

{

}

}

public class img

{

public img()

{ }

public BitmapImage Imgs { get; set; }

}

in Xaml...

 <ScrollViewer Name="sc" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Margin="0,422,0,43">

<ListBox Name="imageList" SelectionChanged="imageList_SelectionChanged_1" Height="126">

<ListBox.ItemsPanel>

<ItemsPanelTemplate >

<StackPanel Orientation="Horizontal"></StackPanel>

</ItemsPanelTemplate>

</ListBox.ItemsPanel>

<ListBox.ItemTemplate>

<DataTemplate >

<StackPanel Orientation="Horizontal">

<Image Margin="10" Name="image1" Source="{Binding Imgs}" Height="150" Width="150"></Image>

</StackPanel>

</DataTemplate>

</ListBox.ItemTemplate>

</ListBox>

</ScrollViewer>

1.All is working perfectly.But the problem is when the page is loading ,it is becoming so slow loading.Even it is taking so much time to load.I need a faster way to load these images,so that images can be loaded in list box in seconds.Actually is there any method of biniding list box images so that it will be loaded fastly. Plsss... help-.....

2.also when refreshing or loading page second time or clicking back button, in getimages() method in picture.getimage() it is showing out of memory exception(I have written in code).

So pls help......

网友答案:

First I'll suggest to check the performance counters using Windows Phone App Profiling & using Windows Phone Application Analysis. These two will give the idea about when and where the performance is hit. Second. there is concept of data virtualization which allows loading of large amount of data virtually. You can find more information about the same here. This link is for Windows app, but pretty much applies to Windows Phone as well.

And last, I'll recommend using MVVM kind of pattern where the view and data will be separate and easy to debug. However, this is not required.

Hope, this helps.

分享给朋友:
您可能感兴趣的文章:
随机阅读: