Any sample code for NSCollectionView Drag and Drop?

Phil John 26 Reputation points
2021-08-04T10:50:10.037+00:00

I'm trying to add drag and drop functionality to my NSCollectionView. I've found a couple of tutorials that deal with the process in Swift, but there are probably at least half a dozen methods to override and I'm finding that the translation to C# is difficult, e.g. even registering the collection view for dragging

in Swift - collectionView.registerForDraggedTypes([NSURLPboardType])

What's the equivalent of NSURLPboardType in Xamarin?

If anyone is aware of a sample project that does this for Mac in C#?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rob Caplan - MSFT 5,542 Reputation points Microsoft Employee
    2021-08-18T00:27:40.167+00:00

    NSURLPBoardType is a string[]

    You can find the binding documentation in the .Net API Explorer at NSView.RegisterForDraggedTypes() Method

    [Foundation.Export("registerForDraggedTypes:")]  
    public virtual void RegisterForDraggedTypes (string[] newTypes);  
    

    This matches Apple's docs, which show NSPasteboardType is a typedeffed string*

    typedef NSString *NSPasteboardType;  
    

    I'm not aware of a full sample, but there is a C# code snippet (unverified and a few years old, but it should get you pointed in the right direction) on StackOverflow in the answer to How I can use a DataObject on MacOS (Drag and Drop files).

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.