question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding injected Pages to a TabbedView

See original GitHub issue

Description

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

  1. Create a MAUI app
  2. Switch MainPage to be a TabbedPage
  3. Create a Page1Vm view model class and a Page1 page class
  4. Add Page1Vm and Page1 as singletons.
  5. Add <Page1 /> as a child of MainPage
  6. 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:closed
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ramonB1996commented, Aug 22, 2022

@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.

1reaction
matt-goldmancommented, Aug 19, 2022

@ramonB1996 can you help here?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found