.NET MAUI 错误没有为此对象定义无参数构造函数

bry*_*jez 11 c# maui .net-maui maui-community-toolkit maui-windows

将我的视图绑定到视图模型时发生。

错误描述:

System.MissingMethodException: 'No parameterless constructor defined for type 'yournamespace.view.pagename'.'
Run Code Online (Sandbox Code Playgroud)

bry*_*jez 37

事实证明我只是忘记将 View 和 ViewModel 注册到 MauiProgram.cs 中

  • @Asmtony,在“MauiProgram.cs”中添加“builder.Services.AddSingleton<PageType>” (3认同)