maui-samples
maui-samples copied to clipboard
FlyOutPage Dependency Injection
Hi,
Trying to apply dependency injection while using FlyOutPage.
In the sample project FlyoutPageSample, I have added a simple class called MyViewModel and added it to the MainPage constructor :
public MainPage(MyViewModel mv) { InitializeComponent(); }
The app will not compile and throws the following error :
Build started... 1>------ Build started: Project: FlyoutPageSample, Configuration: Debug Any CPU ------ 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I tried looking for a working example of dependency injection while using FlyOutPage and did not find any.
Is it not supported yet ? if it does , can we have a working example for it ?
Look at the repository 👍 https://github.com/dotnet-presentations/dotnet-maui-workshop The workshop describes how to accomplish passing a viewmodel to a page constructor
Thanks for your answer.
I looked at the slides and example solutions there and did not find any relevant example using FlyOutPage like the official sample project "FlyoutPageSample".
To be more clear , when not using FlyoutPage , the dependency injection works as described/documented.
But when i do use FlyoutPage , the project wont compile and the errors i attached are shown when trying to compile and not on runtime.
So i am asking again , is there a chance that FlyoutPage not supported/missed out on this ? or there is a working example for DI when using FlyoutPage ?