1

我正在开发一个 Windows 手机应用程序,我从媒体库中收集图像并将每个项目添加到列表框中。

这是我的代码:

  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;
    }

在 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>

一切都在 Windows Phone 7 上完美运行。

它不适用于 Windows Phone 8。

我没有 Windows Phone 8 或 Windows Phone 8 模拟器。我无法下载和安装,因为我没有 Windows 8 操作系统。

  1. 有什么问题?
  2. 或者,有没有办法在 Windows 7 中运行 Windows Phone 8 模拟器?
4

0 回答 0