依赖注入毛伊岛的导航错误

发布于 2025-01-29 02:40:19 字数 792 浏览 2 评论 0原文

我正在将整个应用程序转换为MVVM并添加依赖性 注射。对于导航,我已经使用了

navigation.pushasync(new Date());

它有效但现在不再有效。您有一些解决方案吗?

内部date.xaml.cs


public partial class date : ContentPage
{
    public date(dateViewModel vm)
    {
        InitializeComponent();
        BindingContext = vm;
    }
    
    private void GoNav(object sender, EventArgs e)
    {
        Navigation.PopAsync();
    }
}

c#编译错误是

cs7036没有任何参数对应于“ date.date(dateViewModel)” DateCalculator(net6.0-android),datecalculator(net6.0-ios),datecalculator(net66.0-ios)所需的形式参数“ vm”。 0-Maccatalyst),DateCalculator(Net6.0-Windows10.0.19041.0)C:\ Users \ source \ source \ repos \ datecalculator \ datecalculator \ datecalculator \ mainpage.xaml.xaml.cs 12

I am in the process of transforming my entire application to MVVM and adding Dependency
Injection. for the navigation I have used

Navigation.PushAsync(new date());

it which worked but now its no longer works. do you have some solutions.

inside date.xaml.cs


public partial class date : ContentPage
{
    public date(dateViewModel vm)
    {
        InitializeComponent();
        BindingContext = vm;
    }
    
    private void GoNav(object sender, EventArgs e)
    {
        Navigation.PopAsync();
    }
}

the C# compile error is

CS7036 There is no argument given that corresponds to the required formal parameter 'vm' of 'date.date(dateViewModel)' dateCalculator (net6.0-android), dateCalculator (net6.0-ios), dateCalculator (net6.0-maccatalyst), dateCalculator (net6.0-windows10.0.19041.0) C:\Users\source\repos\dateCalculator\dateCalculator\MainPage.xaml.cs 12

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好听的两个字的网名 2025-02-05 02:40:19

因为

这是因为您删除了默认类构造函数并使用参数创建一个新的,因此当您调用new Date()时,它无法找到构造函数没有参数(默认一个),这就是为什么错误出现的原因。

解决方案

  1. 卸下新的构造函数。

  1. 在创建类时给出参数的值。
      navigation.pushasync(new Date(yourvm));
     

Cause

It is because you remove the default class constructor and create a new one with parameter, so when you call new date() it can't be able to find the constructor without parameter(the default one) , that's why the error comes.

Solution

  1. Remove the new constructor .

Or

  1. Give the value on the parameter when creating the class .
    Navigation.PushAsync(new date(YourVm));
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文