Xamarin.Mac 停靠栏图标不接受拖放文件 [英] Xamarin.Mac dock icon does not accept drag and drop files

查看:25
本文介绍了Xamarin.Mac 停靠栏图标不接受拖放文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序不像其他应用程序那样接受在 Dock 图标上拖放文件.

比如Visual Studio for Mac中的dock图标接受文件,但是当我构建和运行默认项目时,它不接受dock图标的拖放.

也许我需要在 Xcode 中配置一些东西,但我该怎么做?

另外,我应该写什么样的代码来接收拖放到ViewController中的dock图标的文件路径?

解决方案

我自己解决了这个问题.

首先,打开你项目中的info.plist,点击窗口底部的Advanced标签,然后Add Document Type按钮.

Class项中选择Document,对于Identifier,输入public.item.对于Role,将其设置为None.

然后您就可以将其拖放到 Dock 图标上.

然后编写代码就可以在程序端接收拖放的文件了.

AppDelegate.cs

public override void OpenUrls(NSApplication application, NSUrl[] urls){//base.OpenUrls(application, urls);var alert = new NSAlert();alert.MessageText = "AppDelegate.OpenUrls()";alert.InformativeText = urls[0].AbsoluteString;alert.AddButton("确定");alert.RunModal();}

参考.

My application does not accept drag and drop files on the Dock icons like other applications.

For example, the dock icon in Visual Studio for Mac accepts the file, but when I build and run the default project, it does not accept the drag and drop of the dock icon.

Perhaps I need to configure something in Xcode, but how can I do that?

Also, what kind of code should I write to receive the file path dragged and dropped to the dock icon in ViewController?

解决方案

I solved this problem myself.

First, open the info.plist in your project and click the Advanced tab in the bottom of window, and then Add Document Type button.

Select Document in Class item, and for Identifier, enter public.item. For Role, set it to None.

Then you will be able to drag and drop it to the Dock icon.

Then write the code can receive the dragged and dropped files in the program side.

AppDelegate.cs

public override void OpenUrls(NSApplication application, NSUrl[] urls)
{
  //base.OpenUrls(application, urls);
  var alert = new NSAlert();
  alert.MessageText = "AppDelegate.OpenUrls()";
  alert.InformativeText = urls[0].AbsoluteString;
  alert.AddButton("Ok");
  alert.RunModal();
}

ref. https://forums.xamarin.com/discussion/158538/xamarin-mac-appdelegate-openurls-not-invoked

Now you can receive and view the information about the dragged and dropped files.

这篇关于Xamarin.Mac 停靠栏图标不接受拖放文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆