dotnet / dotnet/maui

TabbedPage: Add Content page with Constructor Dependencies

Open
#7,728 5 comments 0 reactions 0 assignees View on GitHub
area-controls-tabbedpage platform/windows proposal/open
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

The Tabbed Page seems to not support dependency injection

### Steps to Reproduce

Create a Tabbed page like







If the Page requires a Dependency like this

public partial class AddressSelectionPage : ContentPage {
public AddressSelectionPage(ViewModelAddress viewModelAddress) {
InitializeComponent();
}
}

and all the parts are added to the DI framework:

builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();
builder.Services.AddTransient();

I get a Build-Error:
- Missing Default Constructor for AddressSelectionPage
-
![Bildschirmfoto 2022-06-03 um 14 29 19](https://user-images.githubusercontent.com/93578472/171853896-37b08083-d135-4850-adbf-50c3a0c104cc.png)

### Version with bug

6.0 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Windows, I was *not* able test on other platforms

### Affected platform versions

any

### Did you find any workaround?

_No response_

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the XAML TabbedPage containing AddressSelectionPage and the constructor that requires ViewModelAddress, with the shown services registered in DI. Trace the build-time page creation and verify that a TabbedPage can contain pages with constructor dependencies without requiring a default constructor; done means the sample builds successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.