Xamarin ImageView继承的类不能调用getContext

时间:2018-03-02 21:07:36

标签: c# xamarin xamarin.android imageview android-context

```

public class MyImageView : ImageView
{

...

    public override void SetImageResource(int resId)
    {
        var inputBitmap = ProcessImage(ContextCompat.GetDrawable(getContext(), resId));
    }

...

}

```

在编译期间获取错误: Controls/MyImageView.cs(...): error CS0103: The name 'getContext' does not exist in the current context

我做错了什么?

1 个答案:

答案 0 :(得分:1)

Xamarin / C#规范化将是一个名为Context的只读属性

public override void SetImageResource(int resId)
{
    var inputBitmap = ProcessImage(ContextCompat.GetDrawable(Context, resId));
}