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

标签 c# object xamarin definition

我的MKAnnotation注释对象有一个名为IsEmergency的变量,但是当我运行此代码时:

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

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

enter image description here

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

这是完整的错误:

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

最佳答案

该 map 委托(delegate)方法开始传递一个 IMKAnnotation,因此将其转换为您的 MKAnnotation 子类:

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

关于c# - Xamarin C# - IMKAnnotation 不包含 'x' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46418494/

相关文章:

c# - 使用无操作 lambda 表达式来初始化事件是否会阻止 GC?

c# - 读取反序列化的 xml 文件 - 具有一个值数组的类

c# - 从 WPF UserControl 访问 ResourceDictionary

xamarin 从十六进制值设置 View 背景颜色

android - 为什么 BroadcastReceiver 在没有实例的情况下也能工作?

c# - 如何在 WinRT 中制作文件存在转换器

jQuery AJAX dataType :"json"无法使用它......只需使用数组即可

javascript - ES6 对象赋值简化

json - Flutter 从 Json 转换嵌套对象返回 null

Xamarin.Forms 自动完成跨平台