DotNet MAUI MVVM: Deep Dive into MVVM Architecture with .NET MAUI
HTML-код
- Опубликовано: 11 сен 2024
- DotNet MAUI Tutorial Series: • .NET MAUI - Learn DotN...
In this video tutorial, we will explore the implementation of the Model-View-ViewModel (MVVM) pattern in .NET MAUI, a powerful cross-platform framework for mobile app development. We'll dive into the concepts of MVVM and its significance in building robust and maintainable applications. Throughout the tutorial, we'll cover various aspects such as data bindings, commands, navigation, and the utilization of the .NET MAUI MVVM toolkit. We'll compare MVVM with other architectural patterns like MVU and showcase examples and real-world scenarios to demonstrate the effectiveness of MVVM in .NET MAUI. By the end of this tutorial, you'll have a solid understanding of how to leverage the MAUI MVVM framework to develop feature-rich, cross-platform Android applications. So, if you're interested in mastering .NET MAUI MVVM and enhancing your Android development skills, this tutorial is perfect for you. Join us and let's get started on this exciting journey!
The Model-View-ViewModel (MVVM) pattern, a cornerstone of .NET MAUI development, ensures a well-defined separation between three crucial software layers: the view, representing the XAML user interface (UI); the model, encompassing the underlying data; and the viewmodel, serving as the intermediary between the view and the model. Through the power of data bindings defined in XAML, the view and viewmodel establish a seamless connection. In the world of .NET MAUI, this pattern finds its natural home, enabling efficient cross-platform mobile app development.
When implementing a XAML page that displays a clock with the current time, additional code is required. Leveraging the strengths of the MVVM pattern, .NET MAUI apps benefit from seamless data binding between visual objects and the underlying data. In the MVVM mindset, the model and viewmodel classes are typically written in code, while the view is often defined in a XAML file that references properties from the viewmodel through data bindings. MVVM emphasizes the separation of concerns, with the model being unaware of the viewmodel and the viewmodel being unaware of the view. However, it is common to tailor the types exposed by the viewmodel to align with those used in the UI.
In MVVM, viewmodels often implement the INotifyPropertyChanged interface, enabling classes to raise the PropertyChanged event whenever a property changes. The powerful data binding mechanism in .NET MAUI subscribes to this event, ensuring the view stays updated with the latest values.
Two-way data bindings, a hallmark of MVVM, empower interactive views that synchronize with the underlying data model.
In some scenarios, app requirements extend beyond simple property bindings, necessitating user-initiated commands that affect the viewmodel. Traditionally, such commands were handled in the code-behind file through event handlers like Clicked or Tapped. However, the commanding interface provides a more MVVM-friendly approach to command implementation. The viewmodel can expose commands, which are methods executed in response to specific view activities, such as button clicks. These commands are seamlessly bound to buttons or other UI elements through data bindings.
In this comprehensive .NET MAUI MVVM tutorial, we'll explore the nuances of the MVVM pattern, leveraging the extensive .NET MAUI MVVM library and tools. We'll dive into practical examples, including commanding scenarios, to demonstrate the power and flexibility of MVVM within the .NET MAUI framework. Whether you're an Android developer, aiming to create cross-platform mobile apps, or a newcomer to mobile app development, this tutorial equips you with the knowledge and skills to build robust and scalable applications.
Join us on this transformative journey into the world of .NET MAUI MVVM and unlock the full potential of cross-platform mobile app development. Start building your next-generation mobile apps today and embrace the future of Android development with .NET MAUI!
⭐ Join Us on Patreon: www.patreon.com/CodingDroplets
.NET MAUI Tutorial Series:
ruclips.net/video/O3-jFuXqASE/видео.html
best explanation of MVVM ive ever seen. Thank you.
Thank you so much for your kind comment! I'm glad to hear that you found the explanation of the MVVM pattern helpful.
Very soon you gonna be Microsoft MVP. Last 6 months I have tried many tutorials. I also completed some Udemy courses. But your teaching is better than any tutorials on Udemy and RUclips. You are the best. Thank you so much for delivering valuable tutorials for free. ❤❤
Thank you so much for your incredibly kind words! I'm thrilled to hear that you find the tutorials helpful, and I genuinely appreciate your support and encouragement. Your feedback inspires me to continue creating valuable content. Thank you for being a part of this community, and I'm honored to have you as a viewer! ❤️❤️
amen
That's my first video from you and well, I did not have expected to have such a harmonic synergy between explanation and video editing! This really is a game changer! And.. oh yeah, thx for the information btw :D
Thank you for watching our video and for your positive feedback! We're delighted that you found the content engaging.
truly this tutor is genius ❤. This is my first video watching in your channel so liked it n subscribed and become a fan of u, u r a star . expect more content from you. may god bless you.
Thank you so much for your kind words! Happy to hear that you found it helpful. Welcome to the channel, There's plenty more content on the way, so stay tuned! May God bless you too. 😊
@@CodingDroplets sure my dear, I'm going to watch all of your tutorials. It's really very useful.
Thank you so much!
New fan here. Brilliant video and very clear and concise explanations. Thank you!
Thank you so much for your kind words! I'm thrilled to have you as a new fan, and I'm delighted to hear that you found the MAUI MVVM tutorial helpful.
You are a good teacher keep it up ;)
For a second I thought you weren't going to use a command and then boom my ocd fixed haha :p good job.
Thank you so much for your kind words and positive feedback.
Your feedback and support inspire me to keep improving and creating valuable contents.
@@CodingDroplets I hope you stay like this interactive with people even when you become famous dont forget us ehh :)
Thank you so much for your heartwarming comment! I truly appreciate your kind words and support.
Interacting with my viewers and building a strong community is essential to me, and I promise that I'll always strive to stay engaged and responsive, no matter how big my channel grows.
My viewers, like you, are the reason I create content, and your feedback and input are invaluable in shaping the direction of my channel. Your learning and success in your coding journey are my top priorities.
As I continue to grow, I'll always remember the support and encouragement I've received from viewers like you. I'm committed to maintaining this positive and interactive environment and creating content that's helpful and informative.
If you ever have any questions, suggestions, or topics you'd like me to cover in my future videos, please don't hesitate to let me know. Your involvement is what makes our community special.
that was an awesome video. you are a monster in this tech
Thank you so much for your kind words! Glad to know that you liked the video.
Nuevo suscriptor :
Gracias por enseñar me alegra que haya gente como usted.
¡Bienvenido, y muchas gracias por suscribirte! Me alegra mucho que hayas encontrado útil el tutorial. Siempre es un placer ayudar y compartir conocimientos con personas interesadas como tú.
Observable property really made my work easy.
I'm glad to hear that using observable properties made your work easier! They are indeed a powerful feature in MVVM.
Explanation is more than wonderful.
Thank you so much.
Thank you for your kind words! I'm glad you found the explanation helpful.
Best explanation for this subject. I was able to understood all your explanations.
Thank you so much for your kind words! I'm delighted to hear that the explanation was helpful and easy to understand.
Thanks you bro for make this video , this helpme alot for my tesis , im building an medical appoiment i this is so helpfull cause im new on maui and mvvm , ty for make my journey better
You're very welcome! I'm thrilled to hear that the tutorial has been helpful for your medical appointment app and your thesis. It's great that you found the content beneficial as you navigate through MAUI and MVVM.
Great instructions, thanks!
You're welcome!
Thank you for your amazing tutorials. please add a new video about best ways for binding data in mvvm structure. Considering dependency and professionalism.
Thank you for your feedback and for watching the tutorials! I'm glad you find them helpful. Your suggestion for a video on the best practices for data binding in the MVVM structure is excellent, and I'll definitely consider creating one.
8:30 - "John Thomas" - Phahaha. This made me laugh. In UK, that is slang for something else. Excellent video. Thank you so much!
I appreciate your feedback! I'm glad the video brought a smile to your face. I'm not entirely sure about the slang reference you mentioned, as it can vary by region, but I'm pleased to hear that you found the content excellent.
I love you my friend you saved me!
I'm glad to hear that the tutorial was helpful for you! Thank You so much
Really like the way you make the videos.
Thank you so much for your positive feedback! Glad to hear that.
Great video. So much information. I was looking for a part where to attach view to viewmodel instead you created binding context in code behind. This is not pure mvvm. Thank you
Thank you for watching and sharing your feedback with us! We're glad to hear that you found the video informative.
In an upcoming tutorial, we'll dive into the concept of dependency injection and discuss how it can be used to attach the view model to the view in a more loosely coupled manner.
Really great video I learnt and cleared my basics. I request you to make video on the validations of the employee user input. Thanks.
Thank you for your positive feedback! I'm glad to hear that you found the tutorial helpful and that it cleared your basics.
Regarding your request for a video on validating employee user input, that's a great suggestion! Validations are an important aspect of application development, and I'll definitely consider creating a video specifically focused on implementing input validations in the context of employee data.
@@CodingDroplets Thank you Sir
I think here deviated with MVVM pattern. Listview_ItemTapped used in the code behind instead of view model, is it not the deviation from MVVM pattern ?
Thank you for your comment and bringing up an important point about the MVVM pattern.
In MVVM, it's generally recommended to handle events and user interactions in the view model instead of the code-behind. This helps to maintain a separation of concerns and keep the view model responsible for the business logic.
However, it's worth mentioning that the MVVM pattern is flexible, and there can be scenarios where handling events in the code-behind might be appropriate, especially for simpler scenarios or quick prototyping. In that part of the tutorial, the focus might have been more on demonstrating the ListView Tapped functionality.
That being said, it's a good practice to strive for a more pure MVVM implementation by handling events and user interactions in the view model. This promotes better code organization and testability.
Thank you for bringing this up, and I appreciate your attention to detail. If you have any further questions or need clarification, feel free to ask. Happy coding!
great video. easy to follow. thanks.
Thank you so much for your kind words! I'm glad to hear that you found the video great and easy to follow.
Awesome video
Thank You!
so you put vm:viewmodel in xaml and also put it on DataContext on code behind
In the tutorial, I assign the ViewModel to the BindingContext in the code-behind. This ensures that the ViewModel is correctly bound to the view, allowing for proper data binding and interaction. Thanks for watching!
Great video thnkx simplified
Thank you for your feedback! I'm glad you found the video helpful and simplified.
well done , i request you to make a tutorial on crud with sqlite3 also.
Thank you for your kind words and the suggestion! We appreciate your feedback. The idea of creating a tutorial on CRUD operations with SQLite3 in the context of .NET MAUI is a valuable one. We'll certainly consider your request for future content.
Can you provide a complete case of data addition, deletion, modification, and search, teacher?
Thank you for your comment! I appreciate your interest in seeing a complete case example. While the tutorial focused on the basics of MVVM architecture, I'll definitely consider creating more detailed tutorials that cover these specific operations in the future.
DO I need to use this model even when I using a database?
please help
Absolutely, using the MVVM (Model-View-ViewModel) pattern and data binding is still beneficial when working with a database in MAUI. It helps maintain separation of concerns and makes your code more maintainable, even when dealing with data retrieval and storage operations from a database. MVVM can help organize your app's logic and user interface effectively.
If possible, do a search for a typed text and show the result... and then click on this result and open its details on another screen...MVVM. Thank you
Thank you for your suggestion! Performing a search for typed text and demonstrating the display of search results along with the ability to view details on another screen is an excellent idea to explore the MVVM pattern.
I'll definitely consider creating a tutorial that covers this scenario, as it's a common and valuable use case.
Hi Master, can you make a Video MVVM work with EF Core 8.0.2? that will is perfect!
Thank you for your suggestion! I appreciate your interest. It's a valuable topic, and I'll definitely consider creating a tutorial on that.
can I request a tutorial ?
Sometimes you have two viewmodels and you want to pass a value from 1 viewmodel to another one how would you do that?
I have never seen a tutorial about it.
In the last bits of this video you were doing something similar but then you were navigating to that page so it wasn't a problem. like : 25:58 where you had empoyeedetailviewmodel and where passing a value.
Thank you for watching and for your tutorial request! We appreciate your engagement and the interesting topic you've brought up.
To clarify your request, when you mention showing the second view without navigation, are you referring to scenarios where you need to communicate data between two view models within the same page? Or do you have another specific scenario in mind where navigation is not desired?
Understanding the context of your request will help us create a tutorial that best addresses your needs and provides the most relevant solutions.
@@CodingDroplets ok so when you have a view A with a viewmodel A and then a view B with a ViewModel B
Thanks
Thank you for providing further clarification! There are several approaches you can take. Here are a couple of common solutions.
Using Dependency Injection: You can inject ViewModel A into ViewModel B (or vice versa). This way, both ViewModels can share data directly.
Event Aggregator Pattern: ViewModels can communicate through an event bus that acts as a mediator. ViewModel A publishes an event containing the data, and ViewModel B subscribes to that event and receives the data when it's raised.
In our upcoming videos in this series, we'll be discussing in detail about both these options. Stay tuned for the upcoming tutorial, and happy coding!
I’m getting a lot of errors and unexpected using statements that aren’t in the video are required to bind.. could you lend some insight as to why I would be getting an error when I’m trying to populate 11:14
I'm sorry to hear you're encountering errors. You can find the source code for the tutorial at this GitHub repository: github.com/codingdroplets/MauiMvvmDemo.
I recommend cloning the repository and comparing your code to the one provided in the tutorial to identify any differences or missing components that might be causing the errors.
more videos on community toolkit maui.
Thanks for the suggestion! We'll be doing more videos on the Community Toolkit for MAUI soon. Stay tuned!
I wonder if you could demonstrate a simple store for the employee data to have it persist.
Thank you for your comment! I appreciate your interest in a demonstration of persisting employee data in a simple store. I'm planning to cover topics like data persistence and storage in an upcoming video.
how to get source code
github.com/codingdroplets/MauiMvvmDemo
You don't share the code 😢
I appreciate your interest! The source code for the .NET MAUI MVVM tutorial is available on GitHub. You can find it at the following repository:
github.com/codingdroplets/MauiMvvmDemo
thank you @@CodingDroplets🙂
You are very welcome!
how can i select or click on label on collectionview please ?@@CodingDroplets
Are you using Frame inside CollectionView item?
There was nothing "deep" about that "dive".
Thank you for sharing your feedback!
That's not true. This video is short because tutor did not wasting time by slow typing, correcting errors and obssession with naming convetions. He prepared everything beforhand and cut useless section from his videos.