{"id":13327223,"url":"https://github.com/dwarry/ReactiveUiMahAppsDialog","last_synced_at":"2025-03-11T02:32:29.236Z","repository":{"id":146315307,"uuid":"133160724","full_name":"dwarry/ReactiveUiMahAppsDialog","owner":"dwarry","description":"Minimal application demonstrating how to open a MahApps custom dialog from a ReactiveUi Interaction. ","archived":false,"fork":false,"pushed_at":"2018-05-12T16:48:38.000Z","size":22,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T04:51:23.255Z","etag":null,"topics":["mahapps","reactiveui"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwarry.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2018-05-12T15:54:43.000Z","updated_at":"2023-06-20T11:50:12.000Z","dependencies_parsed_at":"2023-07-02T14:30:51.695Z","dependency_job_id":null,"html_url":"https://github.com/dwarry/ReactiveUiMahAppsDialog","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"55f481f55027ad62408ecd97574a15b6d46e2770"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwarry%2FReactiveUiMahAppsDialog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwarry%2FReactiveUiMahAppsDialog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwarry%2FReactiveUiMahAppsDialog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwarry%2FReactiveUiMahAppsDialog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwarry","download_url":"https://codeload.github.com/dwarry/ReactiveUiMahAppsDialog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242959541,"owners_count":20212999,"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":["mahapps","reactiveui"],"created_at":"2024-07-29T18:53:51.554Z","updated_at":"2025-03-11T02:32:28.878Z","avatar_url":"https://github.com/dwarry.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ReactiveUiMahAppsDialog\n\nThis is a minimal project which just demonstrates how to open a custom MahApps dialog using ReactiveUi's Interaction infrastructure. \n\n## MainWindow / MainWindowViewModel\nThis is just a MetroWindow shell to host the TestView\n\n## TestDialog / TestDialogViewModel\nThe custom dialog window with a couple of editable fields. The \"OK\" button only becomes enabled when both fields contain non-whitespace values.\n\n## TestView / TestViewModel\nTestView just contains a button to trigger the dialog. TestViewModel uses ReactiveUi's Interaction class to trigger the dialog and collect the entered data. The TestView declares the handler for this interaction, and uses MahApp's DialogCoordinator to display the dialog. \n\nThe interesting part is in TestView's WhenActivated block in its constructor: \n\n```csharp\n    new DialogParticipationRegistration(this).DisposeWith(d);\n    \n    this.ViewModel.Interaction.RegisterHandler(async interaction =\u003e\n    {\n        var dlg = new CustomDialog {Title = interaction.Input};\n\n        var dlgvm = new TestDialogViewModel((TestDialogViewModel vm, bool wasAccepted) =\u003e\n            {\n                DialogCoordinator.Instance.HideMetroDialogAsync(this, dlg);\n\n                if (wasAccepted)\n                {\n                    interaction.SetOutput(new DialogData{Foo = vm.Foo, BarBaz = vm.BarBaz});\n                }\n                else\n                {\n                     interaction.SetOutput(null);\n                }\n            });\n\n        dlg.Content = new ViewModelViewHost {ViewModel = dlgvm};\n            \n        await DialogCoordinator.Instance.ShowMetroDialogAsync(this, dlg);\n\n        await dlg.WaitUntilUnloadedAsync();\n    }).DisposeWith(d);\n```\n\nThe important bits:\n\n* The view has to register itself with the DialogParticipation class - the MahApps docs show how to do this from the ViewModel, but I prefer ReactiveUi's approach of keeping this in the View. This is dealt with by the nested `DialogParticipationRegistration` class that also unregisters it when the TestView is unloaded. \n* The content of the Dialog is set to be a `ViewModelViewHost` that is initialized with a `TestDialogViewModel` instance, so that ReactiveUi can wire everything up in the normal way. \n* Once we have asked the DialogCoordinator to show the dialog, we have to explicitly wait for it to be unloaded, otherwise ReactiveUi will throw an `UnhandledInteractionException` because the interaction handler will end before the dialog has been closed. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwarry%2FReactiveUiMahAppsDialog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwarry%2FReactiveUiMahAppsDialog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwarry%2FReactiveUiMahAppsDialog/lists"}