Home » Science & Technology » MVVM Dialogs: Showing Dialogs in an MVVM Application with a Dialog Service

MVVM Dialogs: Showing Dialogs in an MVVM Application with a Dialog Service

Written By Brian Lagunas on Monday, Nov 22, 2021 | 08:00 AM

 
In this video, I answer the question "How do I show Dialogs in an MVVM application?" Showing dialogs in an MVVM application is a very common requirement. MVVM dialogs are actually core to any MVVM application. In this video, I show you how to use an MVVM Dialog Service to abstract away the process of creating and showing dialog objects from within a ViewModel. The first step in showing dialogs in an MVVM application is to create an interface that defines your Dialog Service. For example public interface IDialogService { void ShowDialog() } Next you need to create a class that implements your MVVM Dialog Service. public class DialogService : IDialogService { public void ShowDialog() { ... } } Once created you would use this service in your ViewModel to show your MVVM dialogs IDialogService dialogService = new DialogService() dialogService.ShowDialog() In this video, I will walk you through each step reuired to implement a proper MVVM Dialog Service. We will cover: - Creating the MVVM Dialog Service - Showing dialogs using names - Handling Dynamic Dialog Window content - Responding to closing the Dialog within your ViewModel - Passing data to your ViewModel when you close the dialog - Registering ViewModels with your Dialogs - Showing dialogs using a ViewModel Type instead of a name 00:00 - Intro 01:16 - The Demo App 02:54 - Creating the Dialog Service 05:52 - Dynamic Window Content 09:20 - Closing Dialogs with Parameters 14:39 - Strongly Typed Dialogs 21:24 - Automatically creating and assigning Data Context 23:53 - Summary Be sure to watch my new Pluralsight course "Introduction to Prism for WPF": 📺 http://bit.ly/PrismForWpf Sponsor Me on GitHub: 🙏🏼 http://bit.ly/SponsorBrianOnGitHub Follow Me: 🐦 Twitter: http://bit.ly/BrianLagunasOnTwitter 📖 Blog: http://bit.ly/BrianLagunasBlog