/// <summary> /// Getting Data from Drop Event Retrieve File/Other Data Dragged onto CSB window. Returning all data as DraggedData, docPanel Readable data. /// </summary> List <DraggedData> ProcessDraggedData(DragEventArgs e) { List <DraggedData> draggedData = new List <DraggedData>(); Console.WriteLine("[CSB_FileDropDetection]:ProcessDraggedData"); if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (var it in files) { DraggedData data = ParseFileData(it); if (data != null) { draggedData.Add(data); } } return(draggedData); } else if (e.Data.GetDataPresent(DataFormats.Text)) { string files = (string)e.Data.GetData(DataFormats.Text); Console.WriteLine(files); DraggedData data = ParseTextData(files); if (data != null) { draggedData.Add(data); } return(draggedData); } return(null); }
/// <summary> /// Parsing weblink into DraggedData, a docPanel Readable data. Which contains /// Name, Path, Icon /// </summary> /// <param name="path"> path to a web url</param> /// <returns>DraggedData return will be processed in ProcessDraggedData</returns> DraggedData ParseWebLink(string path) { DraggedData returnedData = new DraggedData(); returnedData.Path = path; returnedData.FullName = path; returnedData.Formats = FileFormats.webLink; ImageSource ico = getExtensionIcon(".html", FileFormats.webLink); returnedData.Icon = ico; Console.WriteLine("[CSB_FileDropDetection][ParseTextData]:Name is {0}", returnedData.Name); return(returnedData); }
///////////////////////////////////////////////////////////////////////////////// //Parsing ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Parsing path into DraggedData, a docPanel Readable data. Which contains /// Name, Path, Icon /// </summary> /// <param name="_path"> path to a file/folder data</param> /// <returns>DraggedData return will be processed in ProcessDraggedData</returns> DraggedData ParseFileData(string _path) { Console.WriteLine("[CSB_FileDropDetection][ParseFileData]"); DraggedData returnData = new DraggedData(); // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(_path); //detect whether its a directory or file //Check if this fil is directoryy or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:{0} is a directory", _path); //Display name on doc panel returnData.Name = Path.GetFileName(_path); //Fullname to check wether same docpanel existed returnData.FullName = returnData.Name + ".winDirectory"; //path to execute when doc panel is double clicked returnData.Path = _path; //fileformat store for deserializing data returnData.Formats = FileFormats.folder; //Display icon returnData.Icon = getExtensionIcon(_path, FileFormats.folder); } else { Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:{0} a file", _path); //Display name on doc panel returnData.Name = Path.GetFileNameWithoutExtension(_path); //Fullname to check wether same docpanel existed returnData.FullName = Path.GetFileName(_path); //path to execute when doc panel is double clicked returnData.Path = _path; //fileformat store for deserializing data returnData.Formats = FileFormats.file; //Display icon returnData.Icon = getExtensionIcon(_path, FileFormats.file); } Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:Name is {0}", returnData.Name); Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:Path is {0}", returnData.Path); Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:FullName is {0}", returnData.FullName); Console.WriteLine("[CSB_FileDropDetection][ParseFileData]:Format is {0}", returnData.Formats.ToString()); Console.WriteLine(""); return(returnData); }
private void DoDrag(object sender, MouseButtonEventArgs e) { var grid = sender as GridMap; if (isSeatMapOverview) { return; } var selectedCell = (Coordinates)grid.GetValue(SelectedCellProperty); var cellContent = grid.Children.Cast <ContentPresenter>().SingleOrDefault(x => GetRow(x) == selectedCell.Row && GetColumn(x) == selectedCell.Column); if (cellContent is null || isSeatMapOverview || !(cellContent.Content is IGridMapItem)) { return; } var label = VisualTreeChildrenHelper.FindVisualChildren <Label>(cellContent).SingleOrDefault(); var data = new DraggedData(cellContent.Content); DragDrop.DoDragDrop(label, data, DragDropEffects.All); }