xamarin Essentials:没有超载 > 'OnMainDisplayInfoChanged' 匹配委托 > 'EventHandler<DisplayInfoChangedEventArgs>'

xamarin Essentials: No overload for > 'OnMainDisplayInfoChanged' matches delegate > 'EventHandler<DisplayInfoChangedEventArgs>'

我正在使用我的代码关注 Xamarin 示例:

    public App()
    {
        InitializeComponent();
        DeviceDisplay.MainDisplayInfoChanged += OnMainDisplayInfoChanged;
    }

    void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e)
    {
        var displayInfo = e.DisplayInfo;
    }

据我所知,这与此示例中的相同:

https://docs.microsoft.com/en-us/xamarin/essentials/device-display?context=xamarin%2Fios&tabs=uwp

但是它给我错误信息:

App.xaml.cs(13,13): Error CS0123: No overload for 'OnMainDisplayInfoChanged' matches delegate 'EventHandler' (CS0123)

谁能帮我解释一下这条错误消息的含义,并告诉我是否有办法解决这个问题?

出现此错误是因为您缺少第一个 param,即 object sender。尝试传递完整的方法签名。

private void OnMainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e)
{
   var displayInfo = e.DisplayInfo;
}