Adding injected Pages to a TabbedView
See original GitHub issueDescription
TabbedView expects the children pages to have default constructor.
When a page constructor has an injected view model, it doesn’t seem possible to add it to a TabbedPage.
Steps to Reproduce
- Create a MAUI app
- Switch MainPage to be a TabbedPage
- Create a Page1Vm view model class and a Page1 page class
- Add Page1Vm and Page1 as singletons.
- Add <Page1 /> as a child of MainPage
- You’ll get an error message at compile time
https://github.com/sinsedrix/MauiTests/tree/main/MauiTabbedDI
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 19041
Did you find any workaround?
No
I tried to add a default constructor, but then the view model is not injected.
Relevant log output
Erreur XFC0004 Missing default constructor for "MauiApp1.MainPage". MauiApp1
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Using multiple models in tabs with Razor Pages ...
I've built a web app with Razor Pages using .Net Core 2.1 and Entity Framework. On one of the pages I have a...
Read more >Working with TabbedPages
In order to use this method, you must add the Prism.Navigation.TabbedPages namespace to your ViewModel. using Prism.Navigation.TabbedPages;
Read more >Xamarin Forms #33 Navigation: Tabbed Page - YouTube
Xamarin Forms #33 Navigation: Tabbed Page. 10K views · 1 year ago #CSharp ... Add a comment. ... Dependency Injection with Microsoft.
Read more >How to Build a Tabs Component with React
To start, open src/App.js in a text editor. This is the root component that is injected into the page. All components will start...
Read more >TabbedPage - .NET MAUI
The .NET MAUI TabbedPage consists of a series of pages that are navigable by tabs across the top or bottom of the page,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sinsedrix Okay good to know. I will try this with your reproduction sample this week. Will get back to you.
You could try the Page Resolver package by @matt-goldman in the meantime; https://github.com/matt-goldman/Maui.Plugins.PageResolver
Follow the instructions and try if this resolves your problem 😃 I know you might not want to install a package to get it to work, but this might at least help you continue in your project.
@ramonB1996 can you help here?