这是我在这里的第一篇文章,在这个问候网站上。我是一位经验丰富的 C#、.Net 和 Mono 用户,但在 MonoMac 中是 Noob,我正在尝试编写一个应用程序,它接收 NSView 上的文件夹并使用其路径来处理文件夹内的文件......
MonoMac 框架没有实现draggingEntered:, draggingUpdated:, draggingExited:, prepareForDragOperation:, performDragOperation:, concludeDragOperation: and draggingEnded:
所以我尝试自己实现它们:
[Register("TargetView")]
public class TargetView:NSView
{
private static IntPtr selDraggingEntered = Selector.GetHandle ("draggingEntered:");
private static IntPtr selDraggingUpdated = Selector.GetHandle ("draggingUpdated:");
private static IntPtr selDraggingExited = Selector.GetHandle ("draggingExited:");
private static IntPtr selPrepareForDragOperation = Selector.GetHandle ("prepareForDragOperation:");
private static IntPtr selPerformDragOperation = Selector.GetHandle ("performDragOperation:");
private static IntPtr selConcludeDragOperation = Selector.GetHandle ("concludeDragOperation:");
private static IntPtr selDraggingEnded = Selector.GetHandle ("draggingEnded:");
public TargetView():base(){
}
public TargetView(NSCoder coder):base(coder){
}
public TargetView(NSObjectFlag t):base(t){
}
public TargetView(IntPtr handle):base(handle){
}
public TargetView(RectangleF frameRect):base(frameRect){
}
[Export ("draggingEntered:")]
public virtual NSDragOperation DraggingEntered (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
return (NSDragOperation)Messaging.int_objc_msgSend_int (base.Handle, TargetView.selDraggingEntered, (int)sender.DraggingSourceOperationMask);
}
return (NSDragOperation)Messaging.int_objc_msgSendSuper_int (base.Handle, TargetView.selDraggingEntered, (int)sender.DraggingSourceOperationMask);
}
[Export ("draggingUpdated:")]
public virtual NSDragOperation DraggingUpdated (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
return (NSDragOperation)Messaging.int_objc_msgSend_int (base.Handle, TargetView.selDraggingUpdated, (int)sender.DraggingSourceOperationMask);
}
return (NSDragOperation)Messaging.int_objc_msgSendSuper_int (base.Handle, TargetView.selDraggingUpdated, (int)sender.DraggingSourceOperationMask);
}
[Export ("draggingExited:")]
public virtual void DraggingExited (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
Messaging.void_objc_msgSend_int (base.Handle, TargetView.selDraggingExited, (int)sender.DraggingSourceOperationMask);
}
Messaging.void_objc_msgSendSuper_int (base.Handle, TargetView.selDraggingExited, (int)sender.DraggingSourceOperationMask);
}
[Export ("prepareForDragOperation:")]
public virtual bool PrepareForDragOperation (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
return Messaging.bool_objc_msgSend_int (base.Handle, TargetView.selPrepareForDragOperation, (int)sender.DraggingSourceOperationMask);
}
return Messaging.bool_objc_msgSendSuper_int (base.Handle, TargetView.selPrepareForDragOperation, (int)sender.DraggingSourceOperationMask);
}
[Export ("performDragOperation:")]
public virtual bool PerformDragOperation (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
return Messaging.bool_objc_msgSend_int (base.Handle, TargetView.selPerformDragOperation, (int)sender.DraggingSourceOperationMask);
}
return Messaging.bool_objc_msgSendSuper_int (base.Handle, TargetView.selPerformDragOperation, (int)sender.DraggingSourceOperationMask);
}
[Export ("concludeDragOperation:")]
public virtual void ConcludeDragOperation (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
Messaging.void_objc_msgSend_int (base.Handle, TargetView.selConcludeDragOperation, (int)sender.DraggingSourceOperationMask);
}
Messaging.void_objc_msgSendSuper_int (base.Handle, TargetView.selConcludeDragOperation, (int)sender.DraggingSourceOperationMask);
}
[Export ("draggingEnded:")]
public virtual void DraggingEnded (NSDraggingInfo sender)
{
if (sender == null)
{
throw new ArgumentNullException ("sender");
}
if (this.IsDirectBinding)
{
Messaging.void_objc_msgSend_int (base.Handle, TargetView.selDraggingEnded, (int)sender.DraggingSourceOperationMask);
}
Messaging.void_objc_msgSendSuper_int (base.Handle, TargetView.selDraggingEnded, (int)sender.DraggingSourceOperationMask);
}
}
但是这些方法不会被调用!
我也尝试过,RegisterForDraggedTypes
但我不知道将什么作为类型传递给字符串数组!
请帮我弄清楚。我一直在谷歌搜索 48 !