Exemplo n.º 1
0
        /// <summary>
        /// Displays a folder browser dialog to the user.
        /// </summary>
        /// <param name="description">The description that is displayed inside the folder browser dialog.</param>
        /// <returns>Returns the dialog result and the path that the user has selected.</returns>
        public virtual async Task <DialogResult <string> > ShowFolderBrowseDialogAsync(string description)
        {
            // Since the dialog box must be invoked on the UI thread, the invocation is dispatched to the UI thread
            return(await this.applicationService.CurrentDispatcher.InvokeAsync(() =>
            {
                // Creates the folder browser dialog, shows it to the user and returns the dialog result and the selected path
                using (Forms.FolderBrowserDialog folderBrowserDialog = new Forms.FolderBrowserDialog())
                {
                    // Sets the description of the folder browser dialog
                    folderBrowserDialog.Description = description;

                    // Displays the folder browser dialog to the user and returns the dialog result
                    if (folderBrowserDialog.ShowDialog() == Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
                    {
                        return new DialogResult <string>(DialogResult.Okay, folderBrowserDialog.SelectedPath);
                    }
                    else
                    {
                        return new DialogResult <string>(DialogResult.Cancel, string.Empty);
                    }
                }
            }));
        }
        /// <summary>
        /// Displays a folder browser dialog to the user.
        /// </summary>
        /// <param name="description">The description that is displayed inside the folder browser dialog.</param>
        /// <returns>Returns the dialog result and the path that the user has selected.</returns>
        public virtual async Task<DialogResult<string>> ShowFolderBrowseDialogAsync(string description)
        {
            // Since the dialog box must be invoked on the UI thread, the invocation is dispatched to the UI thread
            return await this.applicationService.CurrentDispatcher.InvokeAsync(() =>
            {
                // Creates the folder browser dialog, shows it to the user and returns the dialog result and the selected path
                using (Forms.FolderBrowserDialog folderBrowserDialog = new Forms.FolderBrowserDialog())
                {
                    // Sets the description of the folder browser dialog
                    folderBrowserDialog.Description = description;

                    // Displays the folder browser dialog to the user and returns the dialog result
                    if (folderBrowserDialog.ShowDialog() == Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath))
                        return new DialogResult<string>(DialogResult.Okay, folderBrowserDialog.SelectedPath);
                    else
                        return new DialogResult<string>(DialogResult.Cancel, string.Empty);
                }
            });
        }
 private void ButtonBrowse_Click(object sender, EventArgs e)
 {
     Forms.FolderBrowserDialog dlg = new Forms.FolderBrowserDialog();
     if (dlg.ShowDialog() == Forms.DialogResult.OK)
     {
         TextBoxPath.Text = dlg.SelectedPath;
     }
 }