我试图通过 xaml 将参数传递给我的 MainPage() 构造函数,但出现错误:“缺少“MyApp.View.MainPage”的默认构造函数
我知道我的 MainPage 代码中缺少无参数构造函数。
以下页面是从 App 类调用的根页面,因此我可以有一个弹出菜单。这是 xaml:
<?xml version="1.0" encoding="utf-8" ?>
<FlyoutPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyApp"
xmlns:view="clr-namespace:MyApp.View"
xmlns:viewmodel="clr-namespace:MyApp.ViewModel"
x:Class="MyApp.View.FlyoutMenuRoot"
Title="FlyoutMenuRoot">
<FlyoutPage.Flyout>
<view:FlyoutMenuPage x:Name="flyoutMenuRoot" />
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage>
<x:Arguments>
<view:MainPage>
<x:Arguments>
<viewmodel:MyAppViewModel />
</x:Arguments>
</view:MainPage>
</x:Arguments>
</NavigationPage>
</FlyoutPage.Detail>
</FlyoutPage>
我很确定
<viewmodel:MyAppViewModel />
行完全错误。我该怎么做才能将 MyAppViewModel 作为参数传递给 MainPage?