【问题标题】:Xamarin C# - IMKAnnotation does not contain a definition for 'x'Xamarin C# - IMKAnnotation 不包含“x”的定义
【发布时间】:2018-03-07 04:58:47
【问题描述】:

我的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

【问题讨论】:

    标签: c# object xamarin definition


    【解决方案1】:

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

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

    【讨论】:

    • SushiHangover 再次来救援!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多