private void ProfileTaskList_Drop(object sender, DragEventArgs e) { if (MainWindow.Instance.AccountGrid.SelectedItem != null) { CharacterProfile profile = (CharacterProfile)MainWindow.Instance.AccountGrid.SelectedItem; DataObject dObj = (DataObject)e.Data; BMTask task = null; bool removeSource = false; // drop originated from the left side 'TaskList' if (dObj.GetDataPresent("PersistentObject")) { Type taskType = (Type)dObj.GetData("PersistentObject"); task = (BMTask)Activator.CreateInstance(taskType); task.SetProfile(profile); } else if (sender == ProfileTaskList)// drop originated from itself. { task = (BMTask)dObj.GetData(dObj.GetFormats().FirstOrDefault()); removeSource = true; } if (task == null) { return; } ListBoxItem targetItem = FindParent <ListBoxItem>((DependencyObject)e.OriginalSource); if (targetItem != null) { BMTask targetTask = (BMTask)targetItem.Content; for (int i = ProfileTaskList.Items.Count - 1; i >= 0; i--) { if (ProfileTaskList.Items[i].Equals(targetTask)) { if (removeSource) { profile.Tasks.Remove(task); } profile.Tasks.Insert(i, task); break; } } } else if (!removeSource) { profile.Tasks.Add(task); } _isDragging = false; e.Handled = true; } }
protected async override void OnDrop(System.Windows.DragEventArgs e) { double currMapX = 0; double currMapY = 0; System.Windows.DataObject d = (System.Windows.DataObject)e.Data; string[] dataFormats = d.GetFormats(); string dataText = d.GetText(); Point position = e.GetPosition(this); GMap.NET.PointLatLng curPosition = FromLocalToLatLng((int)position.X, (int)position.Y); currMapX = curPosition.Lng; currMapY = curPosition.Lat; for (int i = 0; i < dataFormats.Length; i++) { string dragFormat = dataFormats[i]; if (dragFormat.Contains("FormationTree") && dataText == "Actor") { object dragObject = d.GetData(dragFormat); FormationTree formation = dragObject as FormationTree; if (formation == null) { continue; } enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined; SetHighwayFilter(highwayFilter); shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY); if (PointId != null) { shPoint pnt = PointId.point; DeployedFormation deployFormation = new DeployedFormation(); deployFormation.x = pnt.x; deployFormation.y = pnt.y; deployFormation.formation = formation; AtomData atom = await TDSClient.SAGInterface.SAGSignalR.DeployFormationFromTree(VMMainViewModel.Instance.SimulationHubProxy, deployFormation); if (atom != null) { AtomDeployedEventArgs args = new AtomDeployedEventArgs(); args.atom = atom; if (AtomDeployedEvent != null) { AtomDeployedEvent(this, args); } } } return; } } }
private void dg_Student_Drop(object sender, DragEventArgs e) { DataGrid dg = sender as DataGrid; if (dg.SelectedItems.Count == 0) { ModernDialog.ShowMessage("没有选择要分班的记录,请先框选需要指定班级的记录", "消息", MessageBoxButton.OK); return; } // 注册Drop事件用来接收数据。 IDataObject data = new DataObject(); data = e.Data; object obj = data.GetData(typeof(BanJiSummaryModel)); if (obj != null) { bool isShowDialog = true;//是否显示对话框 bool isOverRide = true;//是否替换已有班级信息 foreach (DataRowView item in dg.SelectedItems) { if (!string.IsNullOrEmpty(item.Row["班级编号"].ToString())) { if (isShowDialog) { MessageBoxResult result = ModernDialog.ShowMessage("所选记录中已存在班级信息,是否替换班级信息?", "消息", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Cancel) return; if (result == MessageBoxResult.Yes) { isShowDialog = false; isOverRide = true; } if (result == MessageBoxResult.No) { isShowDialog =isOverRide= false; } } //如果覆盖班级信息 则修改内容 if (isOverRide) { item.Row["班级编号"] = (obj as BanJiSummaryModel).Bjbh; item.Row["班级名称"] = (obj as BanJiSummaryModel).Bjmc; item.Row["是否修改"] = true; } } else { item.Row["班级编号"] = (obj as BanJiSummaryModel).Bjbh; item.Row["班级名称"] = (obj as BanJiSummaryModel).Bjmc; item.Row["是否修改"] = true; } } } }
public void Defaults () { DataObject dobj = new DataObject (); Assert.Throws<SecurityException> (() => dobj.GetFormats (), "GetFormats ()"); Assert.Throws<SecurityException> (() => dobj.GetFormats (true), "GetFormats (true)"); Assert.Throws<SecurityException> (() => dobj.GetFormats (false), "GetFormats (false)"); Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop), "GetData (string)"); Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, true), "GetData (string,true)"); Assert.Throws<SecurityException> (() => dobj.GetData (DataFormats.FileDrop, false), "GetData (string,false)"); Assert.Throws<SecurityException> (() => dobj.GetData (typeof(string)), "GetData (Type)"); Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop), "GetDataPresent (string)"); Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, true), "GetDataPresent (string,true)"); Assert.Throws<SecurityException> (() => dobj.GetDataPresent (DataFormats.FileDrop, false), "GetDataPresent (string,false)"); Assert.Throws<SecurityException> (() => dobj.GetDataPresent (typeof (string)), "GetDataPresent (Type)"); Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop), "SetData (string)"); Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, true), "SetData (string,true)"); Assert.Throws<SecurityException> (() => dobj.SetData (DataFormats.FileDrop, false), "SetData (string,false)"); Assert.Throws<SecurityException> (() => dobj.SetData (typeof (string)), "SetData (Type)"); }
void TextEditor_Drop(object sender, DragEventArgs e) { Point pos = e.GetPosition(sender as IInputElement); System.Windows.DataObject o = e.Data as System.Windows.DataObject; string[] formats = o.GetFormats(); string SAMPLE_FORMAT = "DXUnionPacket.ViewModel.Sample"; string MSI_INSTALL_FORMAT = "DXInstaller.MSIInstaller"; string GONG_DD_FORMAT = "GongSolutions.Wpf.DragDrop.DropInfo"; string text = ""; foreach (string format in formats) { if (format.Equals(SAMPLE_FORMAT)) { if (o.GetDataPresent(SAMPLE_FORMAT)) { lock (sync){ Object oo = o.GetData(SAMPLE_FORMAT); Sample s = o.GetData(SAMPLE_FORMAT, true) as Sample; text = s.Text; break; } } } if (format.Equals(MSI_INSTALL_FORMAT)) { MSIInstaller i = o.GetData(MSI_INSTALL_FORMAT) as MSIInstaller; text = i.Guid; break; } } if (!String.IsNullOrEmpty(text)) { InsertText(text, pos); } }
public static Bitmap GetImageFromDataObject(DataObject dataObject) { try { string[] formats = dataObject.GetFormats(true); if (formats == null || formats.Length == 0) { return(null); } //if (formats.Contains("PNG")) // causes errors when trying to save from recents //{ // Console.WriteLine("PNG"); // using (MemoryStream ms = (MemoryStream)dataObject.GetData("PNG")) // { // ms.Position = 0; // return new Bitmap(ms); // } //} if (formats.Contains("System.Drawing.Bitmap")) { Console.WriteLine("System.Drawing.Bitmap"); Bitmap bitmap = (Bitmap)dataObject.GetData("System.Drawing.Bitmap"); return(bitmap); } else { return(dataObject.GetData(DataFormats.Bitmap) as Bitmap); } } catch { return(null); } }
private void cvs1Drop(object sender, DragEventArgs e) { IDataObject data = new DataObject(); data = e.Data; if (data.GetDataPresent(typeof(Rectangle))) { Rectangle rect = new Rectangle(); rect = data.GetData(typeof(Rectangle)) as Rectangle; //canvas2.Children.Remove(rect); //canvas2.Children.Add(rect); string rectXaml = XamlWriter.Save(rect); StringReader stringReader = new StringReader(rectXaml); XmlReader xmlReader = XmlReader.Create(stringReader); UIElement clonedChild = (UIElement)XamlReader.Load(xmlReader); canvas1.Children.Add(clonedChild); } }
private void TextSelectionToDataObject(object sender, RoutedEventArgs e) { // Create a new data object using one of the overloaded constructors. This particular // overload accepts a string specifying the data format (provided by the DataFormats class), // and an Object (in this case a string) that represents the data to be stored in the data object. var dataObject = new DataObject(DataFormats.Text, sourceTextBox.SelectedText); dataObjectInfoTextBox.Clear(); // Get and display the native data formats (filtering out auto-convertable data formats). dataObjectInfoTextBox.Text = "\nNative data formats present:\n"; foreach (var format in dataObject.GetFormats(false /*autoconvert*/)) dataObjectInfoTextBox.Text += format + "\n"; // Display the data in the data object. dataObjectInfoTextBox.Text += "\nData contents:\n"; dataObjectInfoTextBox.Text += dataObject.GetData(DataFormats.Text, false /*autoconvert*/).ToString(); }
private Bitmap getBitmapFromControlsImage(System.Windows.Controls.Image img) { var d = new System.Windows.DataObject(System.Windows.DataFormats.Bitmap, img.Source, true); var bmp = d.GetData("System.Drawing.Bitmap") as System.Drawing.Bitmap; return(bmp); //MemoryStream ms = null; //JpegBitmapEncoder jpegBitmapEncoder = null; //BitmapEncoder bencoder = new JpegBitmapEncoder(); //Bitmap bmp = null; //BitmapImage bitmapImage = new BitmapImage(); //if ((int)img.Source.Width > 0) //{ // RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap((int)img.Source.Width, // (int)img.Source.Height, // 100, 100, PixelFormats.Default); // renderTargetBitmap.Render(img); // jpegBitmapEncoder = new JpegBitmapEncoder(); // jpegBitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); // bencoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); // using (ms = new MemoryStream()) // { // bencoder.Save(ms); // bmp = new System.Drawing.Bitmap(ms); // } //} //Bitmap bmp2 = new Bitmap(bmp); //bmp.Dispose(); //return bmp2; }
void IDragSourceAdvisor.FinishDrag(DataObject draggedElt, DragDropEffects finalEffects, bool DropOk) { if (this.Mode == DragAndDropSourceMode.ReadOnly) return; if (DropOk == false) return; IList l = _ListBox.ItemsSource as IList; if (l == null) return; object oindex = draggedElt.GetData("OriginalSourceIndex"); if (oindex != null) { l.RemoveAt((int)oindex); return; } List<int> indexes = draggedElt.GetData("OriginalSourceIndexes") as List<int>; if (indexes == null) return; indexes.OrderByDescending(i => i).Apply(ind => l.RemoveAt(ind)); }
private static object TryGetData(DataObject dataObject, string dataFormat) { try { return dataObject.GetData(dataFormat); } catch (OutOfMemoryException) { Trace.TraceError("OutOfMemoryException thrown from DataObject."); } return null; }