所以我寫一個Xamarin
應用程序的價值,我已經建立了一個CustomRenderer
如何檢查是否值類型具有IntPtr.Zero
現在我的方法:
horizontalScrollView.ScrollTo(this.Width, 0);
不斷拋出一個異常:
System.ArgumentException: 'jobject' must not be IntPtr.Zero. 10-21 12:10:41.898 E/AndroidRuntime(15053): Parameter name: jobject 10-21 12:10:41.898 E/AndroidRuntime(15053): at Android.Runtime.JNIEnv.CallIntMethod (intptr,intptr) [0x00010] in /Users/builder/data/lanes/2185/53fce373/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:378 10-21 12:10:41.898 E/AndroidRuntime(15053): at Android.Views.View.get_Width()
所以看例外,從我的斷點我發現,問題是,當我將鼠標懸停在this.Width
我得到'jobject' must not be IntPtr.Zero
而不是integer
,所以我嘗試防守對這個代碼,並做到:
if (this.Width != IntPtr.Zero)
{
horizontalScrollView.ScrollTo(this.Width, 0);
}
但這並不編譯和給我的錯誤:
Operator '!=' cannot be applied to operands of type 'int' and 'IntPtr'
所以我的問題是。有沒有辦法檢查value type
是否等於IntPtr.Zero
?