public void RemoveListener(View targetView, DragAndDropEventHandler callback) { if (!targetEventDictionary.ContainsKey(targetView)) { throw new InvalidOperationException("Fail to RemoveListener"); } InternalDragAndDropEventHandler cb = targetEventDictionary[targetView]; targetEventDictionary.Remove(targetView); if (!Interop.DragAndDrop.RemoveListener(SwigCPtr, View.getCPtr(targetView), new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate <Delegate>(cb)))) { throw new InvalidOperationException("Fail to RemoveListener"); } }
public void AddListener(View targetView, DragAndDropEventHandler callback) { InternalDragAndDropEventHandler cb = (dragEvent) => { DragType type = (DragType)Interop.DragAndDrop.GetAction(dragEvent); DragEvent ev = new DragEvent(); global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(dragEvent); ev.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); if (type == DragType.Enter) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Leave) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Move) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Drop) { ev.DragType = type; ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent); ev.Data = Interop.DragAndDrop.GetData(dragEvent); callback(targetView, ev); } }; targetEventDictionary.Add(targetView, cb); if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView), new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate <Delegate>(cb)))) { throw new InvalidOperationException("Fail to AddListener"); } }