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
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.2" />
<PackageVersion Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.2" />
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" />
paket add Oakrey.Applications.UserPrompts.Custom --version 1.0.2
#r "nuget: Oakrey.Applications.UserPrompts.Custom, 1.0.2"
#:package Oakrey.Applications.UserPrompts.Custom@1.0.2
#addin nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.2
#tool nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.2
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
- Open your project in Visual Studio.
- Navigate to Tools > NuGet Package Manager > Manage NuGet Packages for Solution....
- Search for
Oakrey.Applications.UserPrompts.Customand 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:
- Error →
MsgBoxwithSeverity.ERROR - Warning →
MsgBoxwithSeverity.WARNING - Information →
MsgBoxwithSeverity.INFO - Success →
MsgBoxwithSeverity.SUCCESS - WarningException →
MsgBoxwithSeverity.EXCEPTION - YesNoPrompt →
Prompt.Buttons<YesNo>() - OkCancelPrompt →
Prompt.Buttons<OkCancel>() - InputPrompt →
Prompt.StringPrompt() - ComboPrompt →
Prompt.ComboPrompt()
Logging Integration
All prompt interactions are automatically logged:
- Information and success messages logged at
Informationlevel - Warnings logged at
Warninglevel - Errors logged at
Errorlevel - 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
- Author: Oakrey
- Company: Oakrey
- License: MIT
- Repository: Git Repository
- Project URL: Project Website
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- CommonNet.DependencyInjection (>= 0.10.0)
- Oakrey.Applications.UI (>= 3.0.4)
- Oakrey.Applications.UserPrompts (>= 1.0.0)
- Oakrey.Log (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.