Esempio n. 1
0
        // 选择一个本地文件
        private async void btnPickLocalFile_Click(object sender, RoutedEventArgs e)
        {
            StorageFile file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\hololens.jpg");

            if (_fileOpenPickerUI.CanAddFile(file))
            {
                AddFileResult result = _fileOpenPickerUI.AddFile("myFile", file);

                lblMsg.Text  = "选择的文件: " + file.Name;
                lblMsg.Text += Environment.NewLine;
                lblMsg.Text += "AddFileResult: " + result.ToString();
            }
        }
Esempio n. 2
0
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems != null)
            {
                var addedStickers = e.AddedItems.OfType <Sticker>();

                foreach (var item in addedStickers)
                {
                    if (_pickerUi.CanAddFile(item.File))
                    {
                        _pickerUi.AddFile(item.File.Path, item.File);
                    }
                }
            }

            if (e.RemovedItems != null)
            {
                var removedItems = e.RemovedItems.OfType <Sticker>();

                foreach (var item in removedItems)
                {
                    if (_pickerUi.ContainsFile(item.File.Path))
                    {
                        _pickerUi.RemoveFile(item.File.Path);
                    }
                }
            }
        }
        public async Task Add(PickedFile file)
        {
            IStorageFile f = null;

            if (file.Source == PickedFileSource.Local)
            {
                f = await StorageFile.GetFileFromPathAsync(file.Path);
            }
            else if (file.Source == PickedFileSource.Uri)
            {
                var uri = new Uri(file.Path);
                f = await StorageFile.CreateStreamedFileFromUriAsync(Path.GetFileName(file.Path), uri, RandomAccessStreamReference.CreateFromUri(uri));
            }
            else
            {
                throw new ArgumentException("Unknown File source.", nameof(f));
            }

            lock (syncObject)
            {
                if (fileOpenPickerUI.CanAddFile(f))
                {
                    fileOpenPickerUI.AddFile(file.Path, f);
                }
            }
        }
        /// <summary>
        /// Invoked when the selected collection of files changes.
        /// </summary>
        /// <param name="sender">The GridView instance used to display the available files.</param>
        /// <param name="e">Event data that describes how the selection changed.</param>
        private void HandleSelectedFileChanged(Object sender,
                                               SelectionChangedEventArgs e)
        {
            // Update the picker 'basket' with the newly selected items
            foreach (var addedFile in e.AddedItems.Cast <FileInfo>())
            {
                if (_fileOpenPickerUI.CanAddFile(addedFile.File))
                {
                    _fileOpenPickerUI.AddFile(addedFile.Title, addedFile.File);
                }
            }

            // Update the picker 'basket' to remove any newly removed items
            foreach (var removedFile in e.RemovedItems.Cast <FileInfo>())
            {
                if (_fileOpenPickerUI.ContainsFile(removedFile.Title))
                {
                    _fileOpenPickerUI.RemoveFile(removedFile.Title);
                }
            }
        }