本文整理汇总了C#中System.Windows.DataObject类的典型用法代码示例。如果您正苦于以下问题:C# DataObject类的具体用法?C# DataObject怎么用?C# DataObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataObject类属于System.Windows命名空间,在下文中一共展示了DataObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartDragDrop
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;
}
示例2: DragMouseMove
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);
}
}
}
示例3: GetDataObject
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;
}
示例4: btnCopy_Click
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);
}
示例5: Copy
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;
}
示例6: GetDataObject
public DataObject GetDataObject(UIElement draggedElt)
{
string serializedObject = XamlWriter.Save(draggedElt);
DataObject data = new DataObject(SupportedFormat.Name, serializedObject);
return data;
}
示例7: GetDragDataObject
private DataObject GetDragDataObject(DependencyObject dragSource)
{
String format = (String)Application.Current.Resources["DragAndDropRowHeaderFormat"];
DataObject data = new DataObject();
data.SetData(format, dragSource);
return data;
}
示例8: On_MouseMove
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;
}
示例9: OnMouseMove
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;
}
}
示例10: OnListBoxMouseMove
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);
}
}
示例11: CopyToClipboard
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;
}
}
示例12: OnMouseMove
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;
}
}
示例13: Plugitem_PreviewMouseMove
/// <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
{
}
}
}
示例14: Border_MouseLeftButtonDown
//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);
}
示例15: GetDataObject
public virtual DataObject GetDataObject(UIElement draggedElt)
{
string serializedElt = XamlWriter.Save(draggedElt);
DataObject obj = new DataObject();
obj.SetData(supportedFormat,serializedElt);
return obj;
}