Exemple #1
0
        private async void ImageList_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();

                foreach (var i in items)
                {
                    if (i is Windows.Storage.StorageFile f)
                    {
                        string ext = f.Name.Substring(f.Name.LastIndexOf('.') + 1);
                        switch (ext)
                        {
                        case "jpg":
                        case "jpeg":
                        case "png":
                        case "gif":
                        case "tif":
                        case "tiff":
                            UploadImageViewModel imageVm = await UploadImageViewModel.CreateFromStreamAsync(await f.OpenStreamForReadAsync());

                            ViewModel.AddImage(imageVm);
                            break;

                        default:
                            // TODO: Alert user
                            break;
                        }
                    }
                }
            }
            else if (e.DataView.Contains(StandardDataFormats.Bitmap))
            {
                var item = await e.DataView.GetBitmapAsync();

                if (item != null)
                {
                    UploadImageViewModel imageVm = await UploadImageViewModel.CreateFromStreamAsync((await item.OpenReadAsync()).AsStreamForRead());

                    ViewModel.AddImage(imageVm);
                }
            }
        }
Exemple #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is ShareOperation op)
            {
                shareOp = op;
                if (op.Data.Contains(StandardDataFormats.Bitmap))
                {
                    var item = await op.Data.GetBitmapAsync();

                    if (item != null)
                    {
                        UploadImageViewModel imageVm = await UploadImageViewModel.CreateFromStreamAsync((await item.OpenReadAsync()).AsStreamForRead());

                        ViewModel.AddImage(imageVm);
                    }
                }
                else if (op.Data.Contains(StandardDataFormats.StorageItems))
                {
                    var items = await op.Data.GetStorageItemsAsync();

                    foreach (var i in items)
                    {
                        if (i is Windows.Storage.StorageFile f)
                        {
                            UploadImageViewModel imageVm = await UploadImageViewModel.CreateFromStreamAsync(await f.OpenStreamForReadAsync());

                            ViewModel.AddImage(imageVm);
                        }
                    }
                }
                else
                {
                    shareOp = null;
                    op.ReportError("You can only share images to Imgur.");
                    // TODO: Localize
                }
                op.ReportDataRetrieved();
                // After uploading, you will have to call methods to notify completion.
                // See https://docs.microsoft.com/en-us/windows/uwp/app-to-app/receive-data
            }
            else if (e.Parameter is AccountAlbumViewModel albumVm)
            {
                ViewModel = await UploadViewModel.CreateFromAccountAlbum(albumVm);

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ViewModel)));
            }
            else if (e.Parameter is UploadViewModel upVm)
            {
                ViewModel = upVm;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ViewModel)));
            }
            else if (e.Parameter is ItemViewModel itemVm)
            {
                if (itemVm.IsAlbum)
                {
                    ViewModel = UploadViewModel.CreateFromAlbum(itemVm.Item as Models.Album);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ViewModel)));
                }
            }
            else if (e.Parameter is string albumId)
            {
                ViewModel = await UploadViewModel.CreateFromAlbumId(albumId);

                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ViewModel)));
            }
            else if (e.Parameter is Models.Image img && img != null)
            {
                ViewModel.AddImage(new ImageViewModel(img));
            }
        }