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 <IStorageFile?> SaveFilePickerAsync(FilePickerSaveOptions options)
        {
            using var events = new SystemDialogEvents();

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

            _native.SaveFileDialog((IAvnWindow)_window.Native,
                                   events,
                                   options.Title ?? string.Empty,
                                   suggestedDirectory,
                                   options.SuggestedFileName ?? string.Empty,
                                   PrepareFilterParameter(options.FileTypeChoices));

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

            return(result.FirstOrDefault() is string file
                ? new BclStorageFile(new FileInfo(file))
                : null);
        }