1

I am implementing NSTableView row drag and drop. I am working with the examples here Drag & Drop Reorder Rows on NSTableView.

It's actually going fairly well in that my data source methods are getting called when I drag a row in my table. However I am having trouble using the NSDraggingInfo.EnumerateDraggingItems method from Xamarin.

The example Swift code is:

info.enumerateDraggingItemsWithOptions([], forView: tableView, classes: [NSPasteboardItem.self], searchOptions: [:]) {
    if let str = ($0.0.item as! NSPasteboardItem).stringForType("public.data"), index = Int(str) {
        oldIndexes.append(index)
    }
}

The bit I'm having trouble with is classes: [NSPasteboardItem.self].

The signatures of the Xamarin method are:

EnumerateDraggingItems(NSDraggingItemEnumerationOptions, NSView, NSPasteboardReading[], NSDictionary, NSDraggingEnumerator)
EnumerateDraggingItems(NSDraggingItemEnumerationOptions, NSView, NSArray, NSDictionary, NSDraggingEnumerator)
EnumerateDraggingItems(NSDraggingItemEnumerationOptions, NSView, IntPtr, NSDictionary, NSDraggingEnumerator)

How do I supply the required argument for the classes parameter?

fractor
  • 1,534
  • 2
  • 15
  • 30

1 Answers1

0

It seems that the xamarin version is not correct (looking at the source on github https://github.com/xamarin/xamarin-macios/blob/master/src/AppKit/NSDraggingSession.cs):

EnumerateDraggingItems(NSDraggingItemEnumerationOptions, NSView, NSPasteboardReading[], NSDictionary, NSDraggingEnumerator)

Because the classes parameter should be an array of class definitions not instances. Using this version

EnumerateDraggingItems(NSDraggingItemEnumerationOptions, NSView, NSArray, NSDictionary, NSDraggingEnumerator)

The classes array could be created like this:

var classesArray = NSArray.FromIntPtrs(new IntPtr[] {
    ObjCRuntime.Class.GetHandle(typeof(NSPasteboardItem))
});

Have not tested this.

svn
  • 1,235
  • 10
  • 22