Xamarin C# - IMKAnnotation 不包含 'x' 的定义

Xamarin C# - IMKAnnotation does not contain a definition for 'x'

我的 MKAnnotation annotation 对象有一个名为 IsEmergency 的变量,但是当我 运行 这段代码时:

 if (annotation.IsEmergency == "0")
        {
            //doStuff();
        }

我收到一条错误消息,指出我的 annotation 对象不包含 IsEmergency 的定义。

在我提供的屏幕截图中,您可以看到我的对象包含此变量。

这是完整的错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'IMKAnnotation' does not contain a definition for 'IsEmergency' and no extension method 'IsEmergency' accepting a first argument of type 'IMKAnnotation' could be found (are you missing a using directive or an assembly reference?)       270 Active

该映射委托方法开始传递 IMKAnnotation,因此将其转换为您的 MKAnnotation 子类:

var myAnnotation = annotation as `YourMKAnnotationSubClass`;
if (myAnnotation?.IsEmergency == "0")
{
    //doStuff();
}