public Task <string[]> ShowFileDialogAsync(FileDialog dialog, Window parent)
        {
            var events = new SystemDialogEvents();

            var nativeParent = GetNativeWindow(parent);

            if (dialog is OpenFileDialog ofd)
            {
                _native.OpenFileDialog(nativeParent,
                                       events, ofd.AllowMultiple.AsComBool(),
                                       ofd.Title ?? "",
                                       ofd.Directory ?? "",
                                       ofd.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }
            else
            {
                _native.SaveFileDialog(nativeParent,
                                       events,
                                       dialog.Title ?? "",
                                       dialog.Directory ?? "",
                                       dialog.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result; }));
        }
Exemple #2
0
        public Task <string[]> ShowFileDialogAsync(FileDialog dialog, IWindowBaseImpl parent)
        {
            var events = new SystemDialogEvents();

            if (dialog is OpenFileDialog ofd)
            {
                _native.OpenFileDialog((parent as WindowImpl)?.Native,
                                       events, ofd.AllowMultiple,
                                       ofd.Title ?? "",
                                       ofd.InitialDirectory ?? "",
                                       ofd.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }
            else
            {
                _native.SaveFileDialog((parent as WindowImpl)?.Native,
                                       events,
                                       dialog.Title ?? "",
                                       dialog.InitialDirectory ?? "",
                                       dialog.InitialFileName ?? "",
                                       string.Join(";", dialog.Filters.SelectMany(f => f.Extensions)));
            }

            return(events.Task.ContinueWith(t => { events.Dispose(); return t.Result; }));
        }
        public override async Task <IReadOnlyList <IStorageFile> > OpenFilePickerAsync(FilePickerOpenOptions options)
        {
            using var events = new SystemDialogEvents();

            var suggestedDirectory = options.SuggestedStartLocation?.TryGetUri(out var suggestedDirectoryTmp) == true
                ? suggestedDirectoryTmp.LocalPath : string.Empty;

            _native.OpenFileDialog((IAvnWindow)_window.Native,
                                   events,
                                   options.AllowMultiple.AsComBool(),
                                   options.Title ?? string.Empty,
                                   suggestedDirectory,
                                   string.Empty,
                                   PrepareFilterParameter(options.FileTypeFilter));

            var result = await events.Task.ConfigureAwait(false);

            return(result?.Select(f => new BclStorageFile(new FileInfo(f))).ToArray()
                   ?? Array.Empty <IStorageFile>());
        }