MessageDialogManagerLib 1.0.2

There is a newer version of this package available.
See the version list below for details.
Install-Package MessageDialogManagerLib -Version 1.0.2
dotnet add package MessageDialogManagerLib --version 1.0.2
<PackageReference Include="MessageDialogManagerLib" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MessageDialogManagerLib --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MessageDialogManagerLib, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MessageDialogManagerLib as a Cake Addin
#addin nuget:?package=MessageDialogManagerLib&version=1.0.2

// Install MessageDialogManagerLib as a Cake Tool
#tool nuget:?package=MessageDialogManagerLib&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MessageDialogManagerLib

NuGet .NET Core

MessageDialogManagerLib is a library to easily use dialogs from ViewModels in WPF Mahapps.Metro applications. This library uses Mahapps.Metro to show info, progress, ok/cancel or custom dialog. To show a file browser, this library uses Microsoft.Win32.OpenFileDialog and to show a folder browser, this library uses FolderBrowserEx

Supporting .NET Framework (4.5+) and .NET Core (3.0 and 3.1)

Table of contents

Introduction

In both WPF .NET Framework and .NET Core applications we can use dialogs. The problem comes when you want to show a dialog from a ViewModel, especially when you want to test your ViewModel and dialogs block your tests.

The aim of this project is to offer a library with an interface to easily inject in your ViewModel. Your ViewModel will be independent from dialogs implementations and will be testable without blocks.

Getting Started

To use this library, there are a few options:

To use this library, the WPF application has to use Mahapps.Metro.

The MessageDialogManagerLib uses the IMessageDialogManager interface.

public interface IMessageDialogManager
{
    /// <summary>
    /// Shows a folder browser dialog
    /// </summary>
    /// <param name="title">Sets the title of the dialog</param>
    /// <param name="initialPath">Sets the initial path of the dialog</param>
    /// <returns>Returns if a folder has been selected</returns>
    bool ShowFolderBrowser(string title, string initialPath);

    /// <summary>
    /// Gets the selected folder
    /// </summary>
    string FolderPath { get; set; }

    /// <summary>
    /// Shows a file browser dialog
    /// </summary>
    /// <param name="title">Sets the title of the dialog</param>
    /// <param name="initialPath">Sets the initial path of the dialog</param>
    /// <param name="filter">Sets a filter to show only the files that meet the filter</param>
    /// <returns>Returns if a file has been selected</returns>
    bool ShowFileBrowser(string title, string initialPath, string filter);

    /// <summary>
    /// Gets the selected file
    /// </summary>
    string FilePath { get; set; }

    /// <summary>
    /// Shows a save file dialog
    /// </summary>
    /// <param name="title">Sets the title of the dialog</param>
    /// <param name="initialPath">Sets the initial path of the dialog</param>
    /// <param name="fileName">Sets the file's name</param>
    /// <param name="defaultExt">Sets the default file's extension</param>
    /// <param name="filter">Sets the filter</param>
    /// <returns>Returns if a file has been saved</returns>
    bool ShowSaveFileDialog(string title, string initialPath, string fileName, string defaultExt, string filter);

    /// <summary>
    /// Gets the file to save
    /// </summary>
    string FilePathToSave { get; set; }

    /// <summary>
    /// Shows a ok and cancel dialog
    /// </summary>
    /// <param name="text">Sets the text of the dialog</param>
    /// <param name="title">Sets the title of the dialog</param>
    /// MessageDialogResult.OK if the user clicks OK in the dialog box;
    /// otherwise, MessageDialogResult.Cancel.
    Task<MessageDialogResult> ShowOkCancelDialogAsync(string text, string title);

    /// <summary>
    /// Shows a info dialog
    /// </summary>
    /// <param name="title">Sets the title of the dialog</param>
    /// <param name="message">Sets the message of the dialog</param>
    /// <returns></returns>
    Task ShowInfoDialogAsync(string title, string message);

    /// <summary>
    /// Shows a progress dialog
    /// </summary>
    /// <param name="title">Sets the title of the dialog</param>
    /// <param name="message">Sets the message of the dialog</param>
    /// <returns></returns>
    Task ShowProgress(string title, string message);

    /// <summary>
    /// Updates the progress
    /// </summary>
    /// <param name="progress">Sets de progress</param>
    void UpdateProgress(double progress);

    /// <summary>
    /// Updates the message progress
    /// </summary>
    /// <param name="message">Sets the message progress</param>
    void UpdateMessageProgress(string message);

    /// <summary>
    /// Closes the progress dialog
    /// </summary>
    /// <returns></returns>
    Task CloseProgress();

    /// <summary>
    /// Shows a custom dialog
    /// </summary>
    /// <param name="viewModel">Sets the viewmodel attached to the custom dialog</param>
    /// <returns></returns>
    Task ShowDialogAsync(IDialogViewModel viewModel);
}

To use MessageDialogManagerLib in an application, you can follow this example code. There are others examples in the directory Samples of the solution.

MessageDialogManagerMahapps messageDialogManager = new MessageDialogManagerMahapps(App.Current);
MessageDialogResult result = 
                await messageDialogManager.ShowOkCancelDialogAsync(
                    "Ok Cancel Dialog", 
                    "This is a Ok Cancel Dialog");
if (result == MessageDialogResult.OK)
    await messageDialogManager.ShowInfoDialogAsync("Result", "You select Ok");
else
    await messageDialogManager.ShowInfoDialogAsync("Result", "You select Cancel");

License

Copyright © 2020 Evaristo Cuesta

MessageDialogManagerLib is provided as-is under the MIT license. For more information see LICENSE.

Credits

This project uses Mahapps.Metro and FolderBrowserEx.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 221 12/25/2020
1.0.2 108 11/30/2020
1.0.1 104 11/24/2020
1.0.0 207 10/31/2020