private void Grid_Drop(object sender, DragEventArgs e) { try { var fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); MenuItemInfo menuItem = new MenuItemInfo() { FilePath = fileName }; // 快捷方式需要获取目标文件路径 if (fileName.ToLower().EndsWith("lnk")) { WshShell shell = new WshShell(); IWshShortcut wshShortcut = (IWshShortcut)shell.CreateShortcut(fileName); menuItem.FilePath = wshShortcut.TargetPath; } ImageSource imageSource = SystemIcon.GetImageSource(true, menuItem.FilePath); System.IO.FileInfo file = new System.IO.FileInfo(fileName); if (string.IsNullOrWhiteSpace(file.Extension)) { menuItem.Name = file.Name; } else { menuItem.Name = file.Name.Substring(0, file.Name.Length - file.Extension.Length); } menuItem.Type = MenuItemType.Exe; if (ConfigHelper.AddNewMenuItem(menuItem)) { var btn = AddMenuItem(menuItem); fishButtons.Children.Add(btn); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }