![]() |
VOOZH | about |
dotnet add package Oakrey.Applications.UserPrompts.Custom --version 1.0.4
NuGet\Install-Package Oakrey.Applications.UserPrompts.Custom -Version 1.0.4
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.4" />
<PackageVersion Include="Oakrey.Applications.UserPrompts.Custom" Version="1.0.4" />Directory.Packages.props
<PackageReference Include="Oakrey.Applications.UserPrompts.Custom" />Project file
paket add Oakrey.Applications.UserPrompts.Custom --version 1.0.4
#r "nuget: Oakrey.Applications.UserPrompts.Custom, 1.0.4"
#:package Oakrey.Applications.UserPrompts.Custom@1.0.4
#addin nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.4Install as a Cake Addin
#tool nuget:?package=Oakrey.Applications.UserPrompts.Custom&version=1.0.4Install as a Cake Tool
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.
You can install the package via NuGet Package Manager, Package Manager Console or the .NET CLI.
Oakrey.Applications.UserPrompts.Custom and click Install.Run the following command in your terminal:
dotnet add package Oakrey.Applications.UserPrompts.Custom
Run the following command in your Package Manager Console:
Install-Package Oakrey.Applications.UserPrompts.Custom
This package requires:
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 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;
}
}
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();
}
}
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}");
}
}
The CustomUserPromptService class implements IUserPromptBus and routes prompt requests to the appropriate custom dialog:
MsgBox with Severity.ERRORMsgBox with Severity.WARNINGMsgBox with Severity.INFOMsgBox with Severity.SUCCESSMsgBox with Severity.EXCEPTIONPrompt.Buttons<YesNo>()Prompt.Buttons<OkCancel>()Prompt.StringPrompt()Prompt.ComboPrompt()All prompt interactions are automatically logged:
Information levelWarning levelError levelAll dialogs are invoked on the UI thread using the WPF Dispatcher, ensuring thread-safe operation even when called from background threads.
| 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 |
Contributions are welcome! Feel free to open issues or submit pull requests to improve the package.
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 net10.0-windows7.0 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.