Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to Close Windows from a ViewModel in C#
ChannelBrian LagunasDescription 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
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.
- Channel
- Brian Lagunas
- Category
- Science & Technology
- Duration
- 10:39
- Published
- September 1, 2020
- Views
- 26,937
- Likes
- 576
Tags
Share
This tutorial in other languages
- FRComment fermer Windows à partir d'un ViewModel en C #
- ESCómo cerrar Windows desde un modelo de vista en C #
- PTComo Fechar o Windows a partir de um ViewModel em C #
- ITCome chiudere Windows da un ViewModel in C #
- DEWie zu schließen Windows von einem Ansichtsmodell in C #
- NLHoe wordt Sluit Windows uit een ViewModel in C #
- RUКак закрыть окна из ViewModel в C #
- PLJak zamknąć systemu Windows z ViewModel w C #
- JAどのように閉じるWindowsにC#でのViewModelから
- ARكيفية إغلاق Windows من ViewModel في C #
- HIकैसे बंद Windows के लिए सी # में एक ViewModel से
- IDCara Tutup Windows dari ViewModel di C #