1

A similar question got asked here, but I also would like to know if there is a way to limit this filePicker to 4 images or would I have to implement this by my own?

Thank You

Community
  • 1
  • 1
Ulpin
  • 179
  • 1
  • 14

1 Answers1

0

It's not pretty but it works for now. I've declared two global variables of the type ObservableCollection called myimageList and alt-myImageList. I've just check the size of these collections and proceed from this point on.

That's the code:

        private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
    {
        FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

        if (args != null)
        {
            if (args.Files.Count == 0) return;

            view.Activated -= viewActivated;

            foreach (var item in args.Files)
            {
                // instead of item args.Files[0];
                StorageFile storageFile = item;
                var stream = await storageFile.OpenAsync(FileAccessMode.Read);
                var bitmapImage = new BitmapImage();
                await bitmapImage.SetSourceAsync(stream);

                var wbImage = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
                wbImage.SetSource(stream);

                //var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                //bitmapImage.UriSource = new Uri(item.Path, UriKind.Absolute);

                if (myImageList.Count < 4)
                {
                    myImageList.Add(bitmapImage);
                    alt_myImageList.Add(item);
                    ErrorMessage.Text = "";
                }
                else
                {
                    ErrorMessage.Text = "Please pick not more than 4 pictures";
                }
           }
       }
Ulpin
  • 179
  • 1
  • 14