HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to Close Windows from a ViewModel in C#

26,937 views September 1, 2020 10:39

Watch on YouTube
ChannelBrian Lagunas

Description from the creator

In this video, I answer the popular MVVM question, "How to Close Windows from a ViewModel". When you're developing WPF applications using the MVVM design pattern, the number one rule is "no UI elements in the ViewModel". Well, if I am not allowed to have UI elements in the ViewModel, how on earth do I close windows from a ViewModel? Easy! With a simple layer of adbstraction.

I will teach you how to leverage the power of interfaces to abstract away the Window object from the ViewModel and still have the ability to close Windows from your ViewModel.

Not only that, but we will see how we can even prevent the Window from closing, even when clicking on the Window's close button (the X in the top riht corner of the Window), using business logic in our ViewModel by leveraging the flexibility of our abstraction.

I'll even show you how to reduce code duplication by consolidating our abstraction login into an AttachedProperty which can be used on any Window in our application. Write once, use everywhere!

Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
pluralsight.pxf.io/bE3rB

Sponsor Me:
github.com/sponsors/brianlagunas

Follow Me:
Twitter: twitter.com/brianlagunas
Twitch: twitch.tv/brianlagunas
Blog: brianlagunas.com
GitHub: github.com/brianlagunas

About this tutorial

Brian Lagunas published this 10:39 video tutorial on September 1, 2020. It has been watched 26,937 times on YouTube.

Duration
10:39
Published
September 1, 2020
Views
26,937
Likes
576

Tags

Share

This tutorial in other languages