![]() |
VOOZH | about |
dotnet add package MessageDialogService --version 3.0.0
NuGet\Install-Package MessageDialogService -Version 3.0.0
<PackageReference Include="MessageDialogService" Version="3.0.0" />
<PackageVersion Include="MessageDialogService" Version="3.0.0" />Directory.Packages.props
<PackageReference Include="MessageDialogService" />Project file
paket add MessageDialogService --version 3.0.0
#r "nuget: MessageDialogService, 3.0.0"
#:package MessageDialogService@3.0.0
#addin nuget:?package=MessageDialogService&version=3.0.0Install as a Cake Addin
#tool nuget:?package=MessageDialogService&version=3.0.0Install as a Cake Tool
An abstraction layer for showing message dialogs in .Net applications. This supports WinUI, Android and iOS.
await _messageDialogService.ShowMessage(ct, mb => mb
.Title("Oops!")
.Content("Something went wrong.")
.OkCommand()
);
From left to right: WinUI, iOS and Android.
Here is how to setup the service in your WinUI or mobile apps made with Uno Platform.
Install the MessageDialogService.Uno.WinUI NuGet package.
Create a MessageDialogService instance.
using Windows.ApplicationModel.Resources;
// (...)
var currentWindow = yourWindow; // Get the current window.;
var dispatcherQueue = currentWindow.DispatcherQueue;
var resourceLoader = ResourceLoader.GetForViewIndependentUse();
var resourceResolver = resourceKey => resourceLoader.GetString(resourceKey);
var messageDialogService = new MessageDialogService.MessageDialogService(
dispatcherQueue,
#if __IOS__ || __ANDROID__
new MessageDialogBuilderDelegate(resourceResolver)
#else
// On Windows, the builder delegate needs a window handle.
new MessageDialogBuilderDelegate(
resourceResolver,
WinRT.Interop.WindowNative.GetWindowHandle(currentWindow)
)
#endif
);
Use the service to prompt a message dialog.
await messageDialogService.ShowMessage(ct, mb => mb
.Title("Oops!")
.Content("Something went wrong.")
.OkCommand()
);
If you plan on using the default commands (such as OkCommand()), you need to localize them. Here are the resource keys for the default commands.
| Command | Resource Key | Suggested Value (en) |
|---|---|---|
OkCommand() |
MessageDialog_Ok_Label |
"Ok" |
CancelCommand() |
MessageDialog_Cancel_Label |
"Cancel" |
RetryCommand() |
MessageDialog_Retry_Label |
"Retry" |
CloseCommand() |
MessageDialog_Close_Label |
"Close" |
Here is some code showing how to setup the service using Microsoft.Extensions.DependencyInjection.
private static IServiceCollection AddMessageDialog(this IServiceCollection services)
{
return services
#if __IOS__ || __ANDROID__
.AddSingleton<IMessageDialogBuilderDelegate>(s => new MessageDialogBuilderDelegate(
key => s.GetRequiredService<IStringLocalizer>()[key]
))
#else
.AddSingleton<IMessageDialogBuilderDelegate>(s => new MessageDialogBuilderDelegate(
key => s.GetRequiredService<IStringLocalizer>()[key],
WinRT.Interop.WindowNative.GetWindowHandle(App.Instance.CurrentWindow)
))
#endif
.AddSingleton<IMessageDialogService, MessageDialogService.MessageDialogService>();
}
You can use the AcceptOrDefaultMessageDialogService in test projects to simulate a message dialog that always takes the accept or default command.
Here is some code showing how to set it up using Microsoft.Extensions.DependencyInjection.
First, you'll need to install the MessageDialogService NuGet package in your test project.
private static IServiceCollection AddTestMessageDialog(this IServiceCollection services)
{
return services.AddSingleton<IMessageDialogService, AcceptOrDefaultMessageDialogService>();
}
You can use resource keys for the dialog title and content using TitleResource and ContentResource. This is useful for localization.
await _messageDialogService.ShowMessage(ct, mb => mb
.TitleResource("GenericErrorTitle")
.ContentResource("GenericErrorContent")
.OkCommand()
);
You can get the result of the dialog using ShowMessage. This will return a MessageDialogResult enum value.
var result = await _messageDialogService.ShowMessage(ct, mb => mb
.Title("Logout")
.Content("Are you sure you want to logout?")
.CancelCommand()
.AcceptCommand(acceptResourceKey: "Logout_Confirm")
);
if (result == MessageDialogResult.Accept)
{
// Logout
}
When MessageDialogResult doesn't cover all your needs, you can use your own return type by using the ShowMessage<TResult> method. This will return a TResult value.
public enum CustomDialogResult
{
Option1,
Option2,
Option3,
Option4,
Option5
}
// (...)
var customResult = await _messageDialogService.ShowMessage<CustomDialogResult>(ct, mb => mb
.Title("Some Custom Title")
.Content("Some custom content.")
.Command(CustomDialogResult.Option1, label: "Option 1")
.Command(CustomDialogResult.Option2, label: "Option 2")
.Command(CustomDialogResult.Option3, label: "Option 3")
.Command(CustomDialogResult.Option4, label: "Option 4")
.Command(CustomDialogResult.Option5, label: "Option 5")
);
switch (customResult)
{
// Handle the result.
}
You can use the isDesctructive parameter of the Command and CommandResource methods to make the command red on iOS.
This option has no effect on Windows and Android.
var result = await _messageDialogService.ShowMessage(ct, mb => mb
.Title("Delete")
.Content("Are you sure you want to delete the selected items?")
.CancelCommand()
.Command(MessageDialogResult.Accept, label: "Delete", isDestructive: true)
);
if (result == MessageDialogResult.Accept)
{
// Delete
}
It will look like this:
If you want to know how to setup this service for UWP, you need to use version 1.x.x and check out .
Please consult the for more information about version history.
This project is licensed under the Apache 2.0 license - see the file for details.
Please read for details on the process for contributing to this project.
Be mindful of our .
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 3 NuGet packages that depend on MessageDialogService:
| Package | Downloads |
|---|---|
|
MessageDialogService.Uno
MessageDialogService.Uno |
|
|
MessageDialogService.Uno.WinUI
MessageDialogService.Uno.WinUI |
|
|
Sample.Presentation
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 811 | 1/20/2026 |
| 2.0.0 | 46,244 | 1/2/2024 |
| 2.0.0-feature.Uno5Update.10 | 219 | 12/6/2023 |
| 2.0.0-feature.Uno5Update.8 | 2,291 | 12/5/2023 |
| 2.0.0-feature.Uno5Update.6 | 145 | 11/28/2023 |
| 1.0.3-feature.Uno5Update.2 | 130 | 11/3/2023 |
| 1.0.2 | 26,658 | 9/11/2023 |
| 1.0.1 | 681 | 9/11/2023 |
| 1.0.0 | 714 | 9/11/2023 |
| 0.6.0-dev.58 | 44,939 | 10/26/2022 |
| 0.5.0-feature.update-dotnet... | 247 | 8/31/2022 |
| 0.5.0-feature.dotnet6.45 | 250 | 9/6/2022 |
| 0.5.0-feature.dotnet6.35 | 244 | 9/6/2022 |
| 0.5.0-dev.56 | 249 | 10/18/2022 |
| 0.5.0-dev.54 | 32,579 | 10/11/2022 |
| 0.5.0-dev.52 | 712 | 9/28/2022 |
| 0.5.0-dev.48 | 296 | 9/22/2022 |
| 0.5.0-dev.46 | 279 | 9/7/2022 |
| 0.5.0-dev.35 | 289 | 8/23/2022 |
| 0.5.0-dev.33 | 273 | 8/18/2022 |