Oakrey.Applications.UserPrompts.Custom 1.0.2

dotnet add package Oakrey.Applications.UserPrompts.Custom --version 1.0.2
                    
NuGet\Install-Package Oakrey.Applications.UserPrompts.Custom -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oakrey.Applications.UserPrompts.Custom --version 1.0.2
                    
#r "nuget: Oakrey.Applications.UserPrompts.Custom, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oakrey.Applications.UserPrompts.Custom@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.2
                    
Install as a Cake Tool

Oakrey.Applications.UserPrompts.Custom

A custom WPF implementation of the UserPrompts.Abstractions library, providing styled dialog windows for user interaction. This package uses the Oakrey.Applications.UI custom prompt dialogs with enhanced styling and logging integration.

Features

Custom Styled Dialogs

  • Enhanced UI: Uses custom WPF dialogs from Oakrey.Applications.UI.Prompts
  • Severity-Based Styling: Visual distinction for Info, Warning, Error, Success, and Exception messages
  • Modern Look: Professionally styled dialogs consistent with Oakrey design language

Full Prompt Type Support

  • Information Messages: Info, Warning, Error, Success, and Exception dialogs
  • Questions: Yes/No and Ok/Cancel prompts with custom button styling
  • Input Collection: String input dialogs with validation
  • Selection Dialogs: ComboBox-based selection from multiple options

Integrated Logging

  • Automatic logging of all prompt interactions
  • Records user responses for audit trails
  • Built on Oakrey.Log infrastructure

Thread-Safe UI Interaction

  • Dispatcher-based execution ensures UI thread safety
  • Async/await support for non-blocking operations

Easy Configuration

  • Simple dependency injection setup with one extension method
  • Automatic dispatcher registration
  • Seamless integration with UserPrompts.Abstractions

Installation

You can install the package via NuGet Package Manager, Package Manager Console or the .NET CLI.

NuGet Package Manager

  1. Open your project in Visual Studio.
  2. Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution....
  3. Search for Oakrey.Applications.UserPrompts.Custom and click Install.

.NET CLI

Run the following command in your terminal:

dotnet add package Oakrey.Applications.UserPrompts.Custom

Package Manager Console

Run the following command in your Package Manager Console:

Install-Package Oakrey.Applications.UserPrompts.Custom

Prerequisites

This package requires:

  • Oakrey.Applications.UserPrompts.Abstractions - For interfaces and base types
  • Oakrey.Applications.UI - For custom dialog implementations
  • Oakrey.Log - For logging capabilities

Usage Examples

Dependency Injection Setup

using Microsoft.Extensions.DependencyInjection;
using Oakrey.Applications.UserPrompts.Custom;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Register custom user prompts service
        services.AddCustomUserPromptsService();
        
        // This automatically registers:
        // - WPF Application Dispatcher
        // - IUserPrompter<T> for dependency injection
        // - CustomUserPromptService as IUserPromptBus
    }
}

Using in Your Application

using Oakrey.Applications.UserPrompts;
using Oakrey.Applications.UserPrompts.Results;

public class MyViewModel
{
    private readonly IUserPrompter<MyViewModel> _prompter;

    public MyViewModel(IUserPrompter<MyViewModel> prompter)
    {
        _prompter = prompter;
    }

    // Show information with custom styling
    public async Task ShowInfoAsync()
    {
        await _prompter.InfoAsync("Information", "Operation completed successfully.");
    }

    // Show warning with warning icon and styling
    public async Task ShowWarningAsync()
    {
        await _prompter.WarnAsync("Warning", "This action cannot be undone.");
    }

    // Show error with error icon and styling
    public async Task HandleErrorAsync(Exception ex)
    {
        await _prompter.ErrorAsync("Error", $"An error occurred: {ex.Message}");
    }

    // Show success message
    public async Task ShowSuccessAsync()
    {
        await _prompter.SuccessAsync("Success", "File saved successfully!");
    }

    // Ask Yes/No question with custom buttons
    public async Task<bool> ConfirmDeleteAsync(string fileName)
    {
        var result = await _prompter.AskYesOrNoAsync(
            "Confirm Delete",
            $"Are you sure you want to delete '{fileName}'?");
        
        return result == Result.Yes;
    }

    // Ask Ok/Cancel with custom buttons
    public async Task<bool> ConfirmActionAsync()
    {
        var result = await _prompter.AskOkOrCancelAsync(
            "Confirm Action",
            "Do you want to proceed with this operation?");
        
        return result == Result.Ok;
    }

    // Get user input with custom input dialog
    public async Task<string?> GetUserNameAsync()
    {
        var result = await _prompter.AskForStringAsync(
            "User Name",
            "Please enter your name:");
        
        if (result.Result == Result.Ok)
        {
            return result.Value;
        }
        
        return null;
    }

    // Select from options with custom combo dialog
    public async Task<string?> SelectExportFormatAsync()
    {
        var formats = new[] { "PDF", "Excel", "CSV", "JSON" };
        
        var result = await _prompter.AskForSelectionAsync(
            "Export Format",
            "Select the format for export:",
            formats);
        
        if (result.Result == Result.Ok)
        {
            return result.Value;
        }
        
        return null;
    }
}

Complete Application Example

using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Oakrey.Applications.UserPrompts.Custom;

public partial class App : Application
{
    private IServiceProvider _serviceProvider;

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);

        var services = new ServiceCollection();
        
        // Register custom user prompts
        services.AddCustomUserPromptsService();
        
        // Register your view models
        services.AddTransient<MainViewModel>();
        
        _serviceProvider = services.BuildServiceProvider();
        
        var mainWindow = new MainWindow
        {
            DataContext = _serviceProvider.GetRequiredService<MainViewModel>()
        };
        
        mainWindow.Show();
    }
}

Error Handling with Exception Prompts

public async Task ProcessFileAsync(string filePath)
{
    try
    {
        // Process file...
        await _prompter.SuccessAsync("Success", "File processed successfully.");
    }
    catch (FileNotFoundException ex)
    {
        await _prompter.ErrorAsync("File Not Found", $"The file '{filePath}' was not found.");
    }
    catch (Exception ex)
    {
        // Show exception with detailed error styling
        await _prompter.ExcpetionAsync("Unexpected Error", 
            $"An unexpected error occurred: {ex.Message}");
    }
}

Architecture

CustomUserPromptService

The CustomUserPromptService class implements IUserPromptBus and routes prompt requests to the appropriate custom dialog:

  • ErrorMsgBox with Severity.ERROR
  • WarningMsgBox with Severity.WARNING
  • InformationMsgBox with Severity.INFO
  • SuccessMsgBox with Severity.SUCCESS
  • WarningExceptionMsgBox with Severity.EXCEPTION
  • YesNoPromptPrompt.Buttons<YesNo>()
  • OkCancelPromptPrompt.Buttons<OkCancel>()
  • InputPromptPrompt.StringPrompt()
  • ComboPromptPrompt.ComboPrompt()

Logging Integration

All prompt interactions are automatically logged:

  • Information and success messages logged at Information level
  • Warnings logged at Warning level
  • Errors logged at Error level
  • User responses captured for audit trails

Thread Safety

All dialogs are invoked on the UI thread using the WPF Dispatcher, ensuring thread-safe operation even when called from background threads.

Comparison with UserPrompts.Windows

Feature UserPrompts.Custom UserPrompts.Windows
Dialog Style Custom WPF controls Standard MessageBox
Visual Design Enhanced Oakrey styling Windows native style
Logging Integrated logging No built-in logging
Input Dialogs Custom styled dialogs Basic input dialogs
Severity Icons Custom icons per severity Standard Windows icons
Best For Applications requiring consistent branding Quick implementations

Requirements

  • .NET 10 or higher
  • Windows platform (WPF)
  • Oakrey.Applications.UserPrompts.Abstractions
  • Oakrey.Applications.UI
  • Oakrey.Log

Project Information

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2 66 3/18/2026
1.0.1 76 3/13/2026
1.0.0 76 3/11/2026