Binding MAUI Views to View Models (w/ Dependency Injection!) - MAUI TUTORIALS

  Рет қаралды 5,091

SingletonSean

SingletonSean

Күн бұрын

Пікірлер: 27
@Jwhite1979
@Jwhite1979 11 ай бұрын
Dude, you need a medal.
@leonedev
@leonedev Жыл бұрын
Does this mechanism works also for views or just for pages? Because as of now, it does not works when I inject dependency in a view, it will ALWAYS call the default constructor (i.e. parameterless one). Please I'm hardstuck on this
@m3xpl4y
@m3xpl4y Жыл бұрын
I love your videos. Thank you
@DanmarksBedsteGaming
@DanmarksBedsteGaming 4 ай бұрын
brilliant, applied the same concept for avalonia UI!
@Programmidis
@Programmidis 5 ай бұрын
Fantastic! Thank you so much!
@AndiSprick
@AndiSprick Жыл бұрын
Hi, thanks for the hint. What about the midway, by injecting in the constructor of the code behind. public ProfileView(ProfileViewModel vm) { InitializeComponent(); this.BindingContext = vm; } Or is that not a clean injection?
@DonovanBrown
@DonovanBrown Жыл бұрын
This how I do it. I don’t want logic where I am registering my services. But they both work so you have options.
@billymartin6497
@billymartin6497 11 ай бұрын
I use separate methods for services, views, and view models in the MauiProgram.cs and sometimes will use a separate class altogether if a method gets to big. There is no reason you can't put the extension methods in a separate class instead of having them in your MauiProgram.cs
@jenniferdecota3867
@jenniferdecota3867 6 ай бұрын
Should the AddView extension method also work for Subviews such as swapping ContentViews? I couldn't get it to work. I read Microsoft Maui DI documentation and maybe it isn't recommended for this? But I'm a bit confused ha! So I thought I'd ask :)
@SingletonSean
@SingletonSean 6 ай бұрын
Would be interesting! I'm not sure it'd be possible since the parent views typically have direct references to the sub-views within XAML. I think it would take a lot more than just dependency injection to get that working unfortunately.
@elishamisoi
@elishamisoi 3 ай бұрын
Thank you so much!
@JoseArce-cz4kl
@JoseArce-cz4kl 8 ай бұрын
Why are you registering this using Singleton vs transient?
@SingletonSean
@SingletonSean 8 ай бұрын
Good question! It actually won't make a difference either way. The will only resolve the value once, even if it's registered as transient. That said, I prefer to register it as a Singleton to align with this behavior.
@danielfuentes2119
@danielfuentes2119 Жыл бұрын
Could you make a video on how to extract data from the app.config file in .NET MAUI using .NET 8
@billymartin6497
@billymartin6497 11 ай бұрын
I love this idea and it seems to work well in Shell, but I can't get it to work when using a FlyoutPage. Can you please address this?
@SingletonSean
@SingletonSean 11 ай бұрын
Weird, I will have to look into this!
@billymartin6497
@billymartin6497 11 ай бұрын
@@SingletonSean Thanks. It may have something to do with the navigation. I am using a FlyoutPage ViewModel with a collection of pages. When tapped, the command sets Detail = new NavigationPage.
@billymartin6497
@billymartin6497 11 ай бұрын
Was wondering if you found anything out. Also, since there is no code for binding in the code behind, how can I call a method in the viewmodel from the code behind? I have a map that has no bindings, so I need to change the location in the code behind. Thanks.
@sipepguru
@sipepguru 8 ай бұрын
Why are you even using flyout page when she'll has a flyout option?
@billymartin6497
@billymartin6497 8 ай бұрын
@@sipepguru I am using the Shell flyout. I am just using a collectionview inside it.
@Jeremygrmn
@Jeremygrmn Жыл бұрын
Stil wrapping my head around view model instantiation in WPF vs MAUI. In WPF, you would register a factory in DI and create new instances of a VM using that factory, but in MAUI all the VMs ive seen are singletons. MAUI seems a lot cleaner with much less boilerplate, but definitely a different approach. Makes me feel a bit less in control, which might be a me-problem hahaha
@SingletonSean
@SingletonSean Жыл бұрын
Right! Like even if you register the view model as transient, it acts as a singleton. I suppose this is because the AppShell or something only resolves the view / view model once and then holds on to it? Seems like that should be configurable. I agree, feel like we're a bit less in control hahah
@oliver-münzberg
@oliver-münzberg Жыл бұрын
@@SingletonSean That is not true. What you observe is that the AppShell instance (and there is only one hold by the very only one instance of App) has only a single instance for each ShellItem, which should not be such a surprise. And it is very easy to proove: Duplicate the MainPage ShellItem and change the Title and Route properties and run the application. Voila, when transient you get different instances and when singleton, well guess what.
@bl1c
@bl1c Жыл бұрын
❤❤❤
@SingletonSean
@SingletonSean Жыл бұрын
🙌🙌🙌
Securely Persist Local Data in .NET MAUI (Secure Storage)
9:24
SingletonSean
Рет қаралды 2,2 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 915 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
What is the MVVM pattern, What benefits does MVVM have?
22:38
James Montemagno
Рет қаралды 105 М.
Navigation Made Easy (w/ MVVM) - MAUI TUTORIALS
18:17
SingletonSean
Рет қаралды 9 М.
XAML Data Binding and MVVM Basics (.NET MAUI, WPF, UWP, Xamarin.Forms)
19:15
Dependency Injection Basics in .NET MAUI
10:01
dotnet
Рет қаралды 4,7 М.
Dependency Injection with .NET MAUI Explained! Full Beginner's Guide
19:18
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 58 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 199 М.
Dependency Injection Explained in 7 Minutes
7:11
ArjanCodes
Рет қаралды 70 М.
MVVMS... A Better MVVM? Model-View-ViewModel-Services Explained
14:23
James Montemagno
Рет қаралды 32 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН