I am developing a windows phone app where I am collecting images from media library and adding each item to listbox.
Here is my code:
private ObservableCollection<img> _pictures = new ObservableCollection<img>();
public ObservableCollection<img> Pictures
{
get
{
return _pictures;
}
}
// Constructor
public MainPage()
{
InitializeComponent();
getImages();
}
private void PreventCaching()
{
foreach (var picture in _pictures)
{
picture.Imgs.UriSource = null;
}
}
public void getImages()
{
try
{
PreventCaching();
_pictures.Clear();
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
foreach (var picture in pictures)
{
BitmapImage image = new BitmapImage();
image.SetSource(picture.GetThumbnail());
img mediaImage = new img();
mediaImage.Imgs = image;
_pictures.Add(mediaImage);
}
imageList.ItemsSource = _pictures;
}
catch (Exception ex)
{
}
}
public class img
{
public img()
{ }
public BitmapImage Imgs { get; set; }
}
private void imageList_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
MediaLibrary mediaLibrary = new MediaLibrary();
BitmapImage image = new BitmapImage();
image.SetSource(mediaLibrary.Pictures[imageList.SelectedIndex].GetImage());
image1.Source = image;
}
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>
Everything is working perfectly for Windows Phone 7.
It is not working for Windows Phone 8.
I don't have Windows Phone 8 or a emulator for Windows Phone 8. I'm not able to download and install, because I don't have Windows 8 OS.
- What's the issue?
- Alternatively, is there a way to run Windows Phone 8 emulator in Windows 7?