public void StartDragDrop(ItemsControl source, FrameworkElement sourceItemContainer, object draggedData, Point initialMousePosition) { _topWindow = Window.GetWindow(source); Debug.Assert(_topWindow != null); _source = source; _sourceItemContainer = sourceItemContainer; _initialMousePosition = initialMousePosition; _initialMouseOffset = _initialMousePosition - _sourceItemContainer.TranslatePoint(new Point(0, 0), _topWindow); var data = new DataObject(Format.Name, draggedData); // Adding events to the window to make sure dragged adorner comes up when mouse is not over a drop target. bool previousAllowDrop = _topWindow.AllowDrop; _topWindow.AllowDrop = true; _topWindow.DragEnter += TopWindow_DragEnter; _topWindow.DragOver += TopWindow_DragOver; _topWindow.DragLeave += TopWindow_DragLeave; DragDrop.DoDragDrop(_source, data, DragDropEffects.Move); // Without this call, there would be a bug in the following scenario: Click on a data item, and drag // the mouse very fast outside of the window. When doing this really fast, for some reason I don't get // the Window leave event, and the dragged adorner is left behind. // With this call, the dragged adorner will disappear when we release the mouse outside of the window, // which is when the DoDragDrop synchronous method returns. RemoveDraggedAdorner(); _topWindow.AllowDrop = previousAllowDrop; _topWindow.DragEnter -= TopWindow_DragEnter; _topWindow.DragOver -= TopWindow_DragOver; _topWindow.DragLeave -= TopWindow_DragLeave; }
static void DragMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { return; } if (! startPoints.ContainsKey(sender)) { return; } Point mousePos = e.GetPosition(null); Point startPoint = startPoints[sender]; Vector distance = startPoint - mousePos; if (FarEnoughToStartDrag(distance)) { ListViewItem listViewItem = ((DependencyObject)e.OriginalSource).FindAncestor<ListViewItem>(); if (listViewItem != null) { DataObject dragData = new DataObject("listItem", listViewItem); System.Windows.DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move); } } }
/// <summary> /// 拖拽工具插头 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Plugitem_PreviewMouseMove(object sender,MouseEventArgs e) { if(e.LeftButton == MouseButtonState.Pressed) { try { AbstractCableKit drogKit = Kits_ListBox.SelectedItem as AbstractCableKit; AbstractCableKit kit = (AbstractCableKit)drogKit.Clone(); Grid grid = sender as Grid; var dragData = new DataObject(typeof(AbstractCableKit), kit); Point pos = e.GetPosition(Kits_ListBox); HitTestResult result = VisualTreeHelper.HitTest(Kits_ListBox, pos); if (result == null) return; ListBoxItem listBoxItem = EquipmentUtils.FindVisualParent<ListBoxItem>(result.VisualHit); // Find your actual visual you want to drag DragDropAdorner adorner = new DragDropAdorner(listBoxItem); adornerLayer = AdornerLayer.GetAdornerLayer(this); adornerLayer.Add(adorner); DragDrop.DoDragDrop(grid, dragData, DragDropEffects.Copy); adornerLayer.Remove(adorner); adornerLayer = null; } catch { } } }
private static bool CopyToClipboard(string textData, string rtfData, string htmlData, bool addBoxCutCopyTag) { try { DataObject data = new DataObject(); if (rtfData != null) { data.SetData(DataFormats.Rtf, rtfData); } if (htmlData != null) { data.SetData(DataFormats.Html, htmlData); data.SetText(htmlData); } else { data.SetText(textData); } if (addBoxCutCopyTag) { data.SetData("MSDEVColumnSelect", new object()); } Clipboard.SetDataObject(data, true); return true; } catch (ExternalException) { return false; } }
public static void ToClipboard(this List<FrameworkElement> elements) { var builderTabbedText = new StringBuilder(); var builderCsvText = new StringBuilder(); foreach (var element in elements) { string tabbedText = element.DataContext.ToString(); string csvText = element.DataContext.ToString(); builderTabbedText.AppendLine(tabbedText); builderCsvText.AppendLine(csvText); } // data object to hold our different formats representing the element var dataObject = new DataObject(); dataObject.SetText(builderTabbedText.ToString()); // Convert the CSV text to a UTF-8 byte stream before adding it to the container object. var bytes = Encoding.UTF8.GetBytes(builderCsvText.ToString()); var stream = new System.IO.MemoryStream(bytes); dataObject.SetData(DataFormats.CommaSeparatedValue, stream); // lets start with the text representation // to make is easy we will just assume the object set as the DataContext has the ToString method overrideen and we use that as the text dataObject.SetData(DataFormats.CommaSeparatedValue, stream); // now place our object in the clipboard Clipboard.SetDataObject(dataObject, true); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { Point position = e.GetPosition(this); if ((SystemParameters.MinimumHorizontalDragDistance <= Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) || (SystemParameters.MinimumVerticalDragDistance <= Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y)))) { ToolboxObject aux=(ToolboxObject)this.Content; DataObject dataObject = new DataObject("ObjectType",aux.Type); if (dataObject != null) { DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); } } e.Handled = true; } }
private void lstCourses_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) { try { // Get the current mouse position System.Windows.Point mousePos = e.GetPosition(null); Vector diff = startPoint - mousePos; if (e.LeftButton == MouseButtonState.Pressed && ( Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Get the dragged ListViewItem mDraggedParent = sender as System.Windows.Controls.ListView; System.Windows.Controls.ListViewItem listViewItem = FindAnchestor <System.Windows.Controls.ListViewItem>((DependencyObject)e.OriginalSource); // Find the data behind the ListViewItem System.Windows.Controls.ListViewItem contact = (System.Windows.Controls.ListViewItem)mDraggedParent.ItemContainerGenerator. ItemFromContainer(listViewItem); mDraggedClass = contact; // Initialize the drag & drop operation System.Windows.DataObject dragData = new System.Windows.DataObject("System.Windows.Controls.ListViewItem", contact); System.Windows.DragDrop.DoDragDrop(listViewItem, dragData, System.Windows.DragDropEffects.Move); } } catch { } }
public virtual DataObject GetDataObject(UIElement draggedElt) { string serializedElt = XamlWriter.Save(draggedElt); DataObject obj = new DataObject(); obj.SetData(supportedFormat,serializedElt); return obj; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { Point position = e.GetPosition(this); if ((SystemParameters.MinimumHorizontalDragDistance <= Math.Abs((double)(position.X - this.dragStartPoint.Value.X))) || (SystemParameters.MinimumVerticalDragDistance <= Math.Abs((double)(position.Y - this.dragStartPoint.Value.Y)))) { string xamlString = XamlWriter.Save(this.Content); DataObject dataObject = new DataObject("DESIGNER_ITEM", xamlString); if (dataObject != null) { DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); } } e.Handled = true; } }
private void StartDrag(DependencyObject sender, MouseEventArgs e) { _isDragging = true; DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), "note"); DragDropEffects de = DragDrop.DoDragDrop(sender, data, DragDropEffects.Move); _isDragging = false; }
private void On_MouseMove(object sender, MouseEventArgs e) { base.OnMouseMove(e); if (e.LeftButton != MouseButtonState.Pressed) { this.dragStartPoint = null; } if (this.dragStartPoint.HasValue) { DeviceViewModel viewModel = (sender as Image).DataContext as DeviceViewModel; //if (viewModel.DesignerCanvas != null) // viewModel.DesignerCanvas.Toolbox.SetDefault(); var device = viewModel.Device; if (device.Driver.IsPlaceable == false) return; if (FiresecManager.LibraryConfiguration.Devices.Any(x => x.DriverId == device.DriverUID) == false) return; ElementBase plansElement = new ElementDevice() { DeviceUID = device.UID }; var dataObject = new DataObject("DESIGNER_ITEM", plansElement); DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); } e.Handled = true; }
protected override IDataObject GetDataObject(SharpTreeNode[] nodes) { var data = new DataObject(); var paths = nodes.OfType<FileSystemNode>().Select(n => n.FullPath).ToArray(); data.SetData(DataFormats.FileDrop, paths); return data; }
private void OnListBoxMouseMove(object sender, MouseEventArgs e) { if (!_draggingItem) return; // Get the current mouse position Point mousePosition = e.GetPosition(null); Vector diff = _mouseStartPosition - mousePosition; if (e.LeftButton == MouseButtonState.Pressed && (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)) { var listBoxItem = VisualTreeUtility.FindParent<ListBoxItem>( (DependencyObject) e.OriginalSource); if (listBoxItem == null) return; var itemViewModel = (ToolboxItemViewModel) ListBox.ItemContainerGenerator. ItemFromContainer(listBoxItem); var dragData = new DataObject(ToolboxDragDrop.DataFormat, itemViewModel.Model); DragDrop.DoDragDrop(listBoxItem, dragData, DragDropEffects.Move); } }
public DataObject BuildDesktopInternetShortcutDragger(string filetitle, string url) { // The magic happens here thanks to: http://www.codeproject.com/KB/cs/draginternetshortcut.aspx byte[] title = Encoding.ASCII.GetBytes(filetitle + ".url"); var fileGroupDescriptor = new byte[336]; title.CopyTo(fileGroupDescriptor, 76); fileGroupDescriptor[0] = 0x1; fileGroupDescriptor[4] = 0x40; fileGroupDescriptor[5] = 0x80; fileGroupDescriptor[72] = 0x78; var fileGroupDescriptorStream = new MemoryStream(fileGroupDescriptor); byte[] urlByteArray = Encoding.ASCII.GetBytes(url); var urlStream = new MemoryStream(urlByteArray); string contents = "[InternetShortcut]" + Environment.NewLine + "URL=" + url + Environment.NewLine; byte[] contentsByteArray = Encoding.ASCII.GetBytes(contents); var contentsStream = new MemoryStream(contentsByteArray); var dataobj = new DataObject(); dataobj.SetData("FileGroupDescriptor", fileGroupDescriptorStream); dataobj.SetData("FileContents", contentsStream); dataobj.SetData("UniformResourceLocator", urlStream); return dataobj; }
public DataObject GetDataObject(UIElement draggedElt) { string serializedObject = XamlWriter.Save(draggedElt); DataObject data = new DataObject(SupportedFormat.Name, serializedObject); return data; }
private void CopyToClipboard(object sender, RoutedEventArgs args) { var dataObject = new DataObject(); // Copy data from RichTextBox/File content into DataObject if ((bool) rbCopyDataFromRichTextBox.IsChecked) { CopyDataFromRichTextBox(dataObject); } else { CopyDataFromFile(dataObject); } // Copy DataObject on the system Clipboard if (dataObject.GetFormats().Length > 0) { if ((bool) cbFlushOnCopy.IsChecked) { // Copy data to the system clipboard with flush Clipboard.SetDataObject(dataObject, true /*copy*/); } else { // Copy data to the system clipboard without flush Clipboard.SetDataObject(dataObject, false /*copy*/); } } // Dump the copied data contents on the information panel DumpAllClipboardContentsInternal(); }
public MainWindow() { InitializeComponent(); DataObject.AddPastingHandler(OutputFilenameBox, OutputFilenameBox_Paste); FFMpeg.Instance.FFMpegPath = Path.Combine(Environment.CurrentDirectory, "ffmpeg\\ffmpeg.exe"); FFMpeg.Instance.FFProbePath = Path.Combine(Environment.CurrentDirectory, "ffmpeg\\ffprobe.exe"); }
public void startDrag(object sender, System.Windows.Input.MouseEventArgs e) { if (SelectedLandmark != null) { //DataObj mi je Landmark, //Prvi arg je landmarkView //treba da nadjem odg landmarkview, enkapsuliram ga //i to je to. //nalazim odg lview DataObject capsule = new DataObject("landmark", map.GetLandmark(SelectedLandmark)); LandmarkView lw = null; foreach (var v in Goal.Children) { lw = v as LandmarkView; if (lw != null) { if (lw.LandmarkId.Equals(SelectedLandmark)) { break; } } } mapDragAddHandlers = true; DragDrop.DoDragDrop(lw, capsule, DragDropEffects.Move); } }
/// <summary> /// /// </summary> /// <param name="shapes"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="properties"></param> /// <param name="ic"></param> public void SetClipboard( IEnumerable <BaseShape> shapes, double width, double height, ImmutableArray <ShapeProperty> properties, IImageCache ic) { try { using (var bitmap = new Bitmap((int)width, (int)height)) { using (var ms = MakeMetafileStream(bitmap, shapes, properties, ic)) { var data = new WPF.DataObject(); data.SetData(WPF.DataFormats.EnhancedMetafile, ms); WPF.Clipboard.SetDataObject(data, true); } } } catch (Exception ex) { Debug.Print(ex.Message); Debug.Print(ex.StackTrace); } }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="ic"></param> public void SetClipboard(IPageContainer container, IImageCache ic) { try { if (container == null || container.Template == null) { return; } using (var bitmap = new Bitmap((int)container.Template.Width, (int)container.Template.Height)) { using (var ms = MakeMetafileStream(bitmap, container, ic)) { var data = new WPF.DataObject(); data.SetData(WPF.DataFormats.EnhancedMetafile, ms); WPF.Clipboard.SetDataObject(data, true); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } }
private DataObject GetDragDataObject(DependencyObject dragSource) { String format = (String)Application.Current.Resources["DragAndDropRowHeaderFormat"]; DataObject data = new DataObject(); data.SetData(format, dragSource); return data; }
public override IDataObject Copy(SharpTreeNode[] nodes) { var data = new DataObject(); var paths = SharpTreeNode.ActiveNodes.Cast<FileSystemNode>().Select(n => n.FullPath).ToArray(); data.SetData(typeof(string[]), paths); return data; }
private void btnCopy_Click(object sender, RoutedEventArgs e) { var data = new DataObject(); data.SetText(RTF, TextDataFormat.Rtf); data.SetText(rtf.Text, TextDataFormat.Text); Clipboard.SetDataObject(data); }
private void TreeFolderBrowser_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { var selected = TreeFolderBrowser.SelectedItem as PathItem; // only drag image files if (selected == null || selected.IsFolder) { return; } var mousePos = e.GetPosition(null); var diff = startPoint - mousePos; if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) { var treeView = sender as TreeView; var treeViewItem = FindCommonVisualAncestor((DependencyObject)e.OriginalSource); if (treeView == null || treeViewItem == null) { return; } var dragData = new DataObject(DataFormats.UnicodeText, selected.FullPath); DragDrop.DoDragDrop(treeViewItem, dragData, DragDropEffects.Copy); } } }
//http://stackoverflow.com/questions/1719013/obtaining-dodragdrop-dragsource //In the call to DoDragDrop, add your object as an extra format: // var dragSource = this; // var data = "Hello"; // var dataObj = new DataObject(data); // dataObj.SetData("DragSource", dragSource); // DragDrop.DoDragDrop(dragSource, dataObj, DragDropEffects.Copy); //Now in the OnDrag handler it is easy to get the drag source: //protected override void OnDrop(DragEventArgs e) //{ // var data = e.Data.GetData(DataFormats.Text); // var dragSource = e.Data.GetData("DragSource"); // ... //} //In some cases, knowing the source object itself is sufficient to get the data you require to complete the drag operation, in which case the above boils down to: // DragDrop.DoDragDrop(dragSource, dragSource, DragDropEffects.Copy); // ... // var dragSource = e.Data.GetData(typeof(MyDragSource)) private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Label l_Label = sender as Label; var l_DataObject = new DataObject(l_Label.Content); l_DataObject.SetData("String", l_Label.Content); DragDrop.DoDragDrop((System.Windows.DependencyObject)sender, l_DataObject, DragDropEffects.Copy); }
void AssociatedObject_MouseLeave(object sender, MouseEventArgs e) { if (this._isMouseClicked) { // set the item's DataContext as the data to be transferred. var dragObject = this.AssociatedObject.DataContext as IDragable; if (dragObject != null) { this._wasDragging = true; var data = new DataObject(); var parent = ItemsControl.ItemsControlFromItemContainer(this.AssociatedObject) as ListBox; IList list = null; if (this.DragSourceBinding == null) { // Pass the raw ItemSource as the drag object. list = (IList)Activator.CreateInstance((typeof(List <>).MakeGenericType(dragObject.DataType))); if (!this.AssociatedObject.IsSelected) { list.Add(this.AssociatedObject.DataContext); } foreach (var item in parent.SelectedItems) { list.Add(item); } } else { // Pass the Binding object under the ItemSource as the drag object. var propertyName = ((Binding)this.DragSourceBinding as Binding).Path.Path; var pd = TypeDescriptor.GetProperties(this.AssociatedObject.DataContext).Find(propertyName, false); list = (IList)Activator.CreateInstance((typeof(List <>).MakeGenericType(pd.PropertyType))); if (!this.AssociatedObject.IsSelected) { list.Add(pd.GetValue(this.AssociatedObject.DataContext)); } foreach (var item in parent.SelectedItems) { list.Add(pd.GetValue(item)); } } data.SetData(list.GetType(), list); // Send the ListBox that initiated the drag, so we can determine if the drag and drop are different or not. data.SetData(typeof(string), parent.Uid); //data.SetData(dragObject.DataType, this.AssociatedObject.DataContext); System.Windows.DragDrop.DoDragDrop(parent, data, DragDropEffects.Copy); //System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move); } } this._isMouseClicked = false; }
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; } } }
public void AppendData(string format, object data) { if (_data == null) { _data = new DataObject(); } _data.SetData(format, data); }
private void StaticListPanel_MouseMove_1(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DataObject data = new DataObject(sender); DragDrop.DoDragDrop(sender as StaticListPanel, data, DragDropEffects.Link); } }
public void Flush() { if (_data != null) { Clipboard.SetDataObject(_data, true); _data = null; } }
public DragDropHandler(FrameworkElement dragElement, DataObject dataObject) { this.dragElement = dragElement; this.dataObject = dataObject; dragElement.MouseLeftButtonDown += new MouseButtonEventHandler(dragElement_MouseLeftButtonDown); dragElement.MouseMove += new MouseEventHandler(dragElement_MouseMove); }
//Handle filedrop to GUI private void Window_Drop(object sender, System.Windows.DragEventArgs e) { XMlControler xmlcon = new XMlControler(); EDIControler Edicon = new EDIControler(); LWFilepatchtoFinich.Items.Clear(); System.Windows.DataObject dataObject = e.Data as System.Windows.DataObject; LbResultat.Visibility = System.Windows.Visibility.Hidden; List <string> imageFiles = new List <string>(); try { if (dataObject.ContainsFileDropList()) { System.Collections.Specialized.StringCollection fileNames = dataObject.GetFileDropList(); foreach (string fileName in fileNames) { string extension = System.IO.Path.GetExtension(fileName).ToString().ToLower(); switch (extension) { case ".xml": imageFiles.Add(fileName); xmlcon.DecodeBase64(fileName, folman.GetUserFilePatch()); LWFilepatchtoFinich.Items.Add(fileName.ToString()); break; case ".fnx": imageFiles.Add(fileName); xmlcon.DecodeBase64(fileName, folman.GetUserFilePatch()); LWFilepatchtoFinich.Items.Add(fileName.ToString()); break; case ".edi": imageFiles.Add(fileName); Edicon.ExtractEDIFIle(fileName, folman.GetUserFilePatch()); LWFilepatchtoFinich.Items.Add(fileName.ToString()); break; default: LWFilepatchtoFinich.Items.Add("forkert fil format"); break; } } } LbResultat.Visibility = System.Windows.Visibility.Visible; LbResultat.Content = "Færdig"; LbResultat.Foreground = new SolidColorBrush(Colors.Green); } catch { LbResultat.Visibility = System.Windows.Visibility.Visible; LbResultat.Content = "Ingen output"; LbResultat.Foreground = new SolidColorBrush(Colors.Red); } }
private void List_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && LvSongList.SelectedItems != null) { DataObject obj = new DataObject(); obj.SetData(typeof (ObservableCollection<Song>), LvSongList.SelectedItems); DragDrop.DoDragDrop(LvSongList, obj, DragDropEffects.Copy | DragDropEffects.Move); } }
private static void DragDropBehavior_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DependencyObject _sender = sender as DependencyObject; DataObject data = new DataObject(DragDropBehaviorFormat, _sender.GetValue(DragObjectProperty)); DragDrop.DoDragDrop(_sender, data, (DragDropEffects)_sender.GetValue(DragEffectProperty)); } }
private void materialPreview_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { System.Windows.DataObject dataObject = new System.Windows.DataObject(); dataObject.SetData("Object", material); DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Copy); } }
private void HandlePreviewDropCommand(DataObject droppedObject) { if (!droppedObject.ContainsFileDropList()) return; foreach (var filePath in droppedObject.GetFileDropList()) { LocalPhotos.Add(new SinglePhotoFlickrMatchesViewModel(filePath, _flickrModel)); } }
public DataObject GetDataObject(UIElement draggedElt, Point p) { _draggedElt = draggedElt; _serializedElt = XamlWriter.Save(_draggedElt); DataObject obj = new DataObject("CanvasExample", _serializedElt); return obj; }
private void Target_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (unlocked) { DataObject capsule = new DataObject("toolBarTray", Target); ToolBarTray tbt = Target; DragDrop.DoDragDrop(tbt, capsule, DragDropEffects.Move); } }
private void elements_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { object o = e.OriginalSource; AlElement content = Extensions.FindAnchestor<AlElement>((UIElement)o); if (content != null) { DataObject data = new DataObject("AlElement", content); DragDrop.DoDragDrop((UIElement)sender, data, DragDropEffects.Copy); } }
//drag/drop protected override void OnMouseDown(MouseButtonEventArgs e) { Tiles t = UtilityFunctions.GetAncestorOfType<Tiles>(this); GameWindow w = UtilityFunctions.GetAncestorOfType<GameWindow>(this); if (t != null || ((w != null) && w.WordInPlay.ContainsValue(this))) { DataObject thisTileData = new DataObject("scTile", this); DragDrop.DoDragDrop(this, thisTileData, DragDropEffects.Move); } }
private void label1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point mousePos = e.GetPosition(null); Vector diff = startPoint - mousePos; if (e.LeftButton == MouseButtonState.Pressed) { DataObject dragData = new DataObject(DataFormats.Text, ((Label)sender).Content); DragDrop.DoDragDrop((Label)sender, dragData, DragDropEffects.Move); } }
private void lightPreview_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { System.Windows.DataObject dataObject = new System.Windows.DataObject(); dataObject.SetData("Object", light); DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Copy); //Console.WriteLine(_elementsCol.ElementAt(gotowe_ListView.SelectedIndex).ToString()); } }
private void HandleDragDelta(object sender, DragContainerEventArgs e) { // Don't actually start the drag unless the mouse has moved for enough away // from the initial MouseDown point. Point currentPoint = e.CurrentPosition; if (Math.Abs(currentPoint.X - dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(currentPoint.Y - dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance) { this.isMouseDown = false; // Since we have to have the data before the drag starts, we don't allow a drag for data that // is not cached to avoid blocking the UI while the data is fetched before the drag starts. if (IsDataAvailable()) { IsInDrag = true; int width = (int)this.RenderSize.Width; int height = (int)this.RenderSize.Height; RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96.0, 96.0, PixelFormats.Pbgra32); // TODO: use actual dpi. rtb.Render(this); ConstrainSize(ref width, ref height, 200); BitmapSource ghostImage = ResizeImage(rtb, width, height); this.CaptureMouse(); Point mousePoint = new Point(0.5 * width, 0.5 * height); #if USE_STANDARD_DRAGDROP var dataObject = new System.Windows.DataObject(); var items = GetData(); foreach (var item in items) { dataObject.SetData(item.Key, item.Value); } DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy); #else try { DragSourceHelper.DoDragDrop(this, ghostImage, mousePoint, DragDropEffects.Copy, GetData()); } catch (COMException) { // DragDropLib is buggy. Fail silently if this happens. } #endif this.ReleaseMouseCapture(); IsInDrag = false; } } }
private void MenuItem_CopyFile_Click(object sender, System.Windows.RoutedEventArgs e) { if (!String.IsNullOrEmpty(_filename)) { string[] file = new string[1]; file[0] = _filename; System.Windows.DataObject dataObject = new System.Windows.DataObject(); dataObject.SetData(System.Windows.DataFormats.FileDrop, file); System.Windows.Clipboard.SetDataObject(dataObject, true); } }
/// <summary> /// Method to invoke when the Copy command is executed. /// </summary> private void Copy() { List <ElementModel> clipData = new List <ElementModel>(); clipData.AddRange(SelectedItems.Select(x => x.ElementModel).ToList()); IDataObject dataObject = new DataObject(ClipboardFormatName); dataObject.SetData(clipData); Clipboard.SetDataObject(dataObject, true); }
public override void Clear() { if (IsExtended) { Control = new sw.DataObject(new DragDropLib.DataObject()); } else { Control = new sw.DataObject(); } Update(); }
private void TableName_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DataObject obj = new DataObject(); object[] dataValues = new object[] { this.GetType(), this }; obj.SetData(DataFormats.Serializable, dataValues); DragDrop.DoDragDrop(this, obj, DragDropEffects.Copy | DragDropEffects.Move); } }
private void CopyToClipboard(bool cut) { string[] files = GetSelection(); if (files != null) { System.Windows.IDataObject data = new System.Windows.DataObject(System.Windows.DataFormats.FileDrop, files); MemoryStream memo = new MemoryStream(4); byte[] bytes = new byte[] { (byte)(cut ? 2 : 5), 0, 0, 0 }; memo.Write(bytes, 0, bytes.Length); data.SetData("Preferred DropEffect", memo); System.Windows.Clipboard.SetDataObject(data, true); } }
private void MonitorIcon_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) { Point MousePosition = e.GetPosition(null); Vector Difference = StartPoint - MousePosition; if (e.LeftButton == MouseButtonState.Pressed && (Math.Abs(Difference.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(Difference.Y) > SystemParameters.MinimumVerticalDragDistance)) { System.Windows.DataObject DragData = new System.Windows.DataObject("MonitorIcon", sender); DragDrop.DoDragDrop((sender as Grid).Parent, DragData, System.Windows.DragDropEffects.Move); } }
/// <summary> /// Sets managed data to a clipboard DataObject. /// </summary> /// <param name="dataObject">The DataObject to set the data on.</param> /// <param name="format">The clipboard format.</param> /// <param name="data">The data object.</param> /// <remarks> /// Because the underlying data store is not storing managed objects, but /// unmanaged ones, this function provides intelligent conversion, allowing /// you to set unmanaged data into the COM implemented IDataObject.</remarks> public static void SetDataEx(this IDataObject dataObject, string format, object data) { DataFormat dataFormat = DataFormats.GetDataFormat(format); // Initialize the format structure var formatETC = new FORMATETC(); formatETC.cfFormat = (short)dataFormat.Id; formatETC.dwAspect = DVASPECT.DVASPECT_CONTENT; formatETC.lindex = -1; formatETC.ptd = IntPtr.Zero; // Try to discover the TYMED from the format and data TYMED tymed = GetCompatibleTymed(format, data); // If a TYMED was found, we can use the system DataObject // to convert our value for us. if (tymed != TYMED.TYMED_NULL) { formatETC.tymed = tymed; // Set data on an empty DataObject instance var conv = new System.Windows.DataObject(); conv.SetData(format, data, true); // Now retrieve the data, using the COM interface. // This will perform a managed to unmanaged conversion for us. STGMEDIUM medium; ((ComIDataObject)conv).GetData(ref formatETC, out medium); try { // Now set the data on our data object ((ComIDataObject)dataObject).SetData(ref formatETC, ref medium, true); } catch { // On exceptions, release the medium ReleaseStgMedium(ref medium); throw; } } else { // Since we couldn't determine a TYMED, this data // is likely custom managed data, and won't be used // by unmanaged code, so we'll use our custom marshaling // implemented by our COM IDataObject extensions. ComDataObjectExtensions.SetManagedData((ComIDataObject)dataObject, format, data); } }
private void OnMouseDrag(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && !IS_DRAGGING) { IS_DRAGGING = true; Console.WriteLine("dragging"); DataObject dataObject = GetDataObject(); dataObject.SetData("ClipboardObject", this); DragDrop.DoDragDrop((Border)sender, dataObject, DragDropEffects.Copy | DragDropEffects.Move); Console.WriteLine("finished"); IS_DRAGGING = false; } // TODO: visual drag effect }
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 void CreateDragHelper( Drawing.Bitmap bitmap, Point startPoint, System.Windows.DataObject dataObject) { ShDragImage shdi = new ShDragImage(); Win32Size size; size.cx = bitmap.Width; size.cy = bitmap.Height; shdi.sizeDragImage = size; Win32Point wpt; wpt.x = (int)startPoint.X; wpt.y = (int)startPoint.Y; shdi.ptOffset = wpt; shdi.crColorKey = Drawing.Color.Magenta.ToArgb(); // This HBITMAP will be managed by the DragDropHelper // as soon as we pass it to InitializeFromBitmap. If we fail // to make the hand off, we'll delete it to prevent a mem leak. IntPtr hbmp = bitmap.GetHbitmap(); shdi.hbmpDragImage = hbmp; try { IDragSourceHelper sourceHelper = (IDragSourceHelper) new DragDropHelper(); try { sourceHelper.InitializeFromBitmap(ref shdi, (System.Runtime.InteropServices.ComTypes.IDataObject)dataObject); } catch (NotImplementedException ex) { throw new Exception("A NotImplementedException was caught. This could be because you forgot to construct your DataObject using a DragDropLib.DataObject", ex); } } catch { // We failed to initialize the drag image, so the DragDropHelper // won't be managing our memory. Release the HBITMAP we allocated. GDI32.DeleteObject(hbmp); } }
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) { base.OnMouseMove(e); if (SelectedFile != null && FilePath == SelectedFile.ItemPath && e.LeftButton == MouseButtonState.Pressed && System.Windows.Forms.Control.ModifierKeys != Keys.Shift && System.Windows.Forms.Control.ModifierKeys != Keys.Control) { // Package the data. string[] files = new string[] { FilePath }; System.Windows.DataObject dataObject = new System.Windows.DataObject(System.Windows.DataFormats.FileDrop, files); DragDrop.DoDragDrop(this, dataObject, System.Windows.DragDropEffects.Copy); } }
private void OnMouseDrag(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && !IS_DRAGGING) { IS_DRAGGING = true; Icon.Visibility = Visibility.Hidden; Console.WriteLine("dragging c"); DataObject dataObject = new DataObject(); dataObject.SetData("Category", this); DragDrop.DoDragDrop((Border)sender, dataObject, DragDropEffects.Copy | DragDropEffects.Move); Console.WriteLine("finished c"); IS_DRAGGING = false; Icon.Visibility = Visibility.Visible; } // TODO: visual drag effect }
/// <summary> /// Method packs selected orders to dragging data object /// </summary> /// <param name="selectedOrers"></param> /// <returns></returns> private IDataObject _CreateDraggingObject(Collection <Order> selectedOrers) { DraggingOrdersObject draggingObject = new DraggingOrdersObject(); draggingObject.OrdersPlannedDate = (DateTime)selectedOrers[0].PlannedDate; draggingObject.IDsCollection = new Collection <Guid>(); foreach (Order order in selectedOrers) { draggingObject.IDsCollection.Add(order.Id); } System.Windows.DataObject newObject = new System.Windows.DataObject(DRAGGING_DATA_FORMAT_STRING, draggingObject); return(newObject); }
public HotsamplingPage() { InitializeComponent(); _resolutionRefreshTimer = new Timer() { Interval = 1000 }; _resolutionRefreshTimer.Tick += _resolutionRefreshTimer_Tick; DataObject.AddCopyingHandler(_newHeightBox, (s, e) => { if (e.IsDragDrop) { e.CancelCommand(); } }); DataObject.AddCopyingHandler(_newWidthBox, (s, e) => { if (e.IsDragDrop) { e.CancelCommand(); } }); }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="ic"></param> public void SetClipboard(Container container, IImageCache ic) { try { using (var bitmap = new Bitmap((int)container.Width, (int)container.Height)) { using (var ms = MakeMetafileStream(bitmap, container, ic)) { var data = new WPF.DataObject(); data.SetData(WPF.DataFormats.EnhancedMetafile, ms); WPF.Clipboard.SetDataObject(data, true); } } } catch (Exception ex) { Debug.Print(ex.Message); Debug.Print(ex.StackTrace); } }
private void ContentView_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { if (!_isDragging && e.LeftButton == MouseButtonState.Pressed) { _isDragging = true; // fake listviewitem System.Windows.Controls.ListViewItem dummy = new System.Windows.Controls.ListViewItem(); // Find the data behind the ListViewItem try { dynamic mediaFile = ContentView.SelectedItem; var path = mediaFile.FullName; Console.WriteLine(path); // Initialize the drag & drop operation System.Windows.DataObject dragData = new System.Windows.DataObject("mediaFile", path); DragDrop.DoDragDrop(dummy, dragData, System.Windows.DragDropEffects.Move); } catch { } } _isDragging = false; }
public DataObject GetDataObject() { DataObject dataObject = new DataObject(); foreach (string format in dataMap.Keys) { try { object data = dataMap[format]; if (data != null) { dataObject.SetData(format, data); } } catch (ExternalException ex) { Console.WriteLine($"Error {ex.ErrorCode}: {ex.Message}"); } } return(dataObject); }