{"id":21730127,"url":"https://github.com/nventive/messagedialogservice","last_synced_at":"2025-10-07T12:31:13.345Z","repository":{"id":42620200,"uuid":"290586133","full_name":"nventive/MessageDialogService","owner":"nventive","description":"Wrapper around Uno's MessageDialog","archived":false,"fork":false,"pushed_at":"2024-02-26T18:59:41.000Z","size":11832,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":26,"default_branch":"main","last_synced_at":"2025-01-22T17:09:24.405Z","etag":null,"topics":["android","dotnet","ios","maui","message-dialog","mobile","uno-platform","uwp","winui"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nventive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-26T19:26:30.000Z","updated_at":"2022-09-22T14:30:26.000Z","dependencies_parsed_at":"2023-01-20T04:46:26.551Z","dependency_job_id":"ffcfc557-9e38-4249-9a85-b7df7498df2f","html_url":"https://github.com/nventive/MessageDialogService","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"nventive/Template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FMessageDialogService","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FMessageDialogService/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FMessageDialogService/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FMessageDialogService/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nventive","download_url":"https://codeload.github.com/nventive/MessageDialogService/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235628177,"owners_count":19020540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dotnet","ios","maui","message-dialog","mobile","uno-platform","uwp","winui"],"created_at":"2024-11-26T04:12:30.310Z","updated_at":"2025-10-07T12:31:12.923Z","avatar_url":"https://github.com/nventive.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Message Dialog Service\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](LICENSE) ![Version](https://img.shields.io/nuget/v/MessageDialogService?style=flat-square) ![Downloads](https://img.shields.io/nuget/dt/MessageDialogService?style=flat-square)\n\nAn abstraction layer for showing message dialogs in .Net applications.\nThis supports WinUI, Android and iOS.\n\n```csharp\nawait _messageDialogService.ShowMessage(ct, mb =\u003e mb\n   .Title(\"Oops!\")\n   .Content(\"Something went wrong.\")\n   .OkCommand()\n);\n```\n\n## Preview\nFrom left to right: WinUI, iOS and Android.\n![](doc/images/dialog.png)\n\n## Getting Started\nHere is how to setup the service in your WinUI or mobile apps made with Uno Platform.\n\n1. Install the `MessageDialogService.Uno.WinUI` NuGet package.\n\n1. Create a `MessageDialogService` instance.\n   \n   ```csharp\n   using Windows.ApplicationModel.Resources;\n   \n   // (...)\n\n   var currentWindow = yourWindow; // Get the current window.;\n   var dispatcherQueue = currentWindow.DispatcherQueue;\n   var resourceLoader = ResourceLoader.GetForViewIndependentUse();\n   var resourceResolver = resourceKey =\u003e resourceLoader.GetString(resourceKey);\n\n   var messageDialogService = new MessageDialogService.MessageDialogService(\n      dispatcherQueue,   \n   #if __IOS__ || __ANDROID__\n      new MessageDialogBuilderDelegate(resourceResolver)\n   #else\n      // On Windows, the builder delegate needs a window handle.\n      new MessageDialogBuilderDelegate(\n         resourceResolver,\n         WinRT.Interop.WindowNative.GetWindowHandle(currentWindow)\n      )\n   #endif\n   );\n   ```\n\n1. Use the service to prompt a message dialog.\n   \n   ```csharp\n   await messageDialogService.ShowMessage(ct, mb =\u003e mb\n      .Title(\"Oops!\")\n      .Content(\"Something went wrong.\")\n      .OkCommand()\n   );\n   ```\n\n## Next Steps\n\n### Localize the Default Buttons\nIf you plan on using the default commands (such as `OkCommand()`), you need to localize them. Here are the resource keys for the default commands.\n\n| Command | Resource Key | Suggested Value (en) |\n| ------- | ------------ | -------------------- |\n| `OkCommand()` | `MessageDialog_Ok_Label` | `\"Ok\"` |\n| `CancelCommand()` | `MessageDialog_Cancel_Label` | `\"Cancel\"` |\n| `RetryCommand()` | `MessageDialog_Retry_Label` | `\"Retry\"` |\n| `CloseCommand()` | `MessageDialog_Close_Label` | `\"Close\"` |\n\n### Setup the Service using Dependency Injection\nHere is some code showing how to setup the service using `Microsoft.Extensions.DependencyInjection`.\n\n```csharp\nprivate static IServiceCollection AddMessageDialog(this IServiceCollection services)\n{\n   return services\n#if __IOS__ || __ANDROID__\n      .AddSingleton\u003cIMessageDialogBuilderDelegate\u003e(s =\u003e new MessageDialogBuilderDelegate(\n         key =\u003e s.GetRequiredService\u003cIStringLocalizer\u003e()[key]\n      ))\n#else\n      .AddSingleton\u003cIMessageDialogBuilderDelegate\u003e(s =\u003e new MessageDialogBuilderDelegate(\n         key =\u003e s.GetRequiredService\u003cIStringLocalizer\u003e()[key],\n         WinRT.Interop.WindowNative.GetWindowHandle(App.Instance.CurrentWindow)\n      ))\n#endif\n      .AddSingleton\u003cIMessageDialogService, MessageDialogService.MessageDialogService\u003e();\n}\n```\n\n### Setup the Service in Test Projects\nYou can use the `AcceptOrDefaultMessageDialogService` in test projects to simulate a message dialog that always takes the accept or default command.\n\nHere is some code showing how to set it up using `Microsoft.Extensions.DependencyInjection`.\nFirst, you'll need to install the `MessageDialogService` NuGet package in your test project.\n\n```csharp\nprivate static IServiceCollection AddTestMessageDialog(this IServiceCollection services)\n{\n   return services.AddSingleton\u003cIMessageDialogService, AcceptOrDefaultMessageDialogService\u003e();\n}\n```\n\n\n## Features\n\n### Use Resource Keys for Dialog Content\nYou can use resource keys for the dialog title and content using `TitleResource` and `ContentResource`. This is useful for localization.\n\n```csharp\nawait _messageDialogService.ShowMessage(ct, mb =\u003e mb\n   .TitleResource(\"GenericErrorTitle\")\n   .ContentResource(\"GenericErrorContent\")\n   .OkCommand()\n);\n```\n\n### Get the Result of the Dialog\nYou can get the result of the dialog using `ShowMessage`. This will return a `MessageDialogResult` enum value.\n\n```csharp\nvar result = await _messageDialogService.ShowMessage(ct, mb =\u003e mb\n   .Title(\"Logout\")\n   .Content(\"Are you sure you want to logout?\")\n   .CancelCommand()\n   .AcceptCommand(acceptResourceKey: \"Logout_Confirm\")\n);\n\nif (result == MessageDialogResult.Accept)\n{\n   // Logout\n}\n```\n\n### Use Your Own Return Type\nWhen `MessageDialogResult` doesn't cover all your needs, you can use your own return type by using the `ShowMessage\u003cTResult\u003e` method. This will return a `TResult` value.\n\n```csharp\npublic enum CustomDialogResult\n{\n   Option1,\n   Option2,\n   Option3,\n   Option4,\n   Option5\n}\n\n// (...)\n\nvar customResult = await _messageDialogService.ShowMessage\u003cCustomDialogResult\u003e(ct, mb =\u003e mb\n   .Title(\"Some Custom Title\")\n   .Content(\"Some custom content.\")\n   .Command(CustomDialogResult.Option1, label: \"Option 1\")\n   .Command(CustomDialogResult.Option2, label: \"Option 2\")\n   .Command(CustomDialogResult.Option3, label: \"Option 3\")\n   .Command(CustomDialogResult.Option4, label: \"Option 4\")\n   .Command(CustomDialogResult.Option5, label: \"Option 5\")\n);\n\nswitch (customResult)\n{\n   // Handle the result.\n}\n```\n\n### Highlight Destructive Commands (iOS Only)\nYou can use the `isDesctructive` parameter of the `Command` and `CommandResource` methods to make the command red on iOS.\nThis option has no effect on Windows and Android.\n\n```csharp\nvar result = await _messageDialogService.ShowMessage(ct, mb =\u003e mb\n   .Title(\"Delete\")\n   .Content(\"Are you sure you want to delete the selected items?\")\n   .CancelCommand()\n   .Command(MessageDialogResult.Accept, label: \"Delete\", isDestructive: true)\n);\n\nif (result == MessageDialogResult.Accept)\n{\n   // Delete\n}\n```\n\nIt will look like this:\n![](doc/images/destructive.png)\n\n## Legacy\n\nIf you want to know how to setup this service for UWP, you need to use version 1.x.x and check out [getting started with UWP](doc/GettingStartedUWP.md).\n\n## Changelog\n\nPlease consult the [CHANGELOG](CHANGELOG.md) for more information about version\nhistory.\n\n## License\n\nThis project is licensed under the Apache 2.0 license - see the\n[LICENSE](LICENSE) file for details.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for\ncontributing to this project.\n\nBe mindful of our [Code of Conduct](CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Fmessagedialogservice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnventive%2Fmessagedialogservice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Fmessagedialogservice/lists"}