我最近升级到了Xamarin.Mac Unified API。在升级之前,我通过FolderBrowserDialog
使用System.Windows.Forms
。通过升级,我无法再访问System.Windows.Forms
命名空间。我联系了客户支持,他们建议引用本机API。所以我添加了这个nuget及其依赖项。该nuget的存在消除了以下代码的intellisense错误:
var dir = Environment.SpecialFolder.MyPictures.ToString ();
var dlg = new CommonOpenFileDialog ();
dlg.Title = "Exclude Subdirectories";
dlg.IsFolderPicker = true;
dlg.InitialDirectory = dir;
dlg.AddToMostRecentlyUsedList = false;
dlg.AllowNonFileSystemItems = false;
dlg.DefaultDirectory = dir;
dlg.EnsureFileExists = true;
dlg.EnsurePathExists = true;
dlg.EnsureReadOnly = false;
dlg.EnsureValidNames = true;
dlg.Multiselect = false;
dlg.ShowPlacesList = true;
if (dlg.ShowDialog () == CommonFileDialogResult.Ok) {
var folder = dlg.FileName;
}
但是在运行时它引用了{strong} ole32.dll 的System.DllNotFoundException
。有关如何克服这个问题的任何想法?这link并不能让人充满希望。在这一点上我唯一的选择是恢复到经典的api ......如果我这样做,我不相信它可以放在应用程序商店中。
答案 0 :(得分:0)
根本不需要那个nuget。您可以使用以下代码完成FolderBrowserDialog:
NSOpenPanel openDlg = NSOpenPanel.OpenPanel;
openDlg.Prompt = "Select Directory"; //Defaults to OPEN
openDlg.CanChooseDirectories = true;
openDlg.CanChooseFiles = false;
openDlg.Title = "Choose Monitored Directory";
openDlg.AllowsMultipleSelection = false;
openDlg.CanCreateDirectories = true;
openDlg.ReleasedWhenClosed = true;
openDlg.DirectoryUrl = new NSUrl (Environment.GetFolderPath (System.Environment.SpecialFolder.UserProfile));
openDlg.Begin (result => {
var url = openDlg.Url;
if (result == 1) {
//directory selected
} else {
//cancelled
}
});