本文整理汇总了C#中System.Windows.DataObject类的典型用法代码示例。如果您正苦于以下问题:C# DataObject类的具体用法?C# DataObject怎么用?C# DataObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataObject类属于System.Windows命名空间,在下文中一共展示了DataObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rmunn,项目名称:cog,代码行数:33,代码来源:ItemsControlDragDrop.cs
示例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);
}
}
}
开发者ID:AnthonySteele,项目名称:openwrap,代码行数:25,代码来源:DragHelper.cs
示例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;
}
开发者ID:ratoy,项目名称:SharpDevelop,代码行数:7,代码来源:FileSystemNode.cs
示例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);
}
开发者ID:kehh,项目名称:biolink,代码行数:7,代码来源:RTFReportViewer.xaml.cs
示例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;
}
开发者ID:lujinlong,项目名称:Apq,代码行数:7,代码来源:FileSystemNode.cs
示例6: GetDataObject
public DataObject GetDataObject(UIElement draggedElt)
{
string serializedObject = XamlWriter.Save(draggedElt);
DataObject data = new DataObject(SupportedFormat.Name, serializedObject);
return data;
}
开发者ID:liuxr,项目名称:wpfumprototype,代码行数:7,代码来源:DefaultDragSourceAdvisor.cs
示例7: GetDragDataObject
private DataObject GetDragDataObject(DependencyObject dragSource)
{
String format = (String)Application.Current.Resources["DragAndDropRowHeaderFormat"];
DataObject data = new DataObject();
data.SetData(format, dragSource);
return data;
}
开发者ID:cardsurf,项目名称:WindNote,代码行数:7,代码来源:DragableRowHeaderMouseMoveHandler.cs
示例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;
}
开发者ID:hjlfmy,项目名称:Rubezh,代码行数:31,代码来源:DevicesView.xaml.cs
示例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;
}
}
开发者ID:AaronRevilla,项目名称:TT_2012b-049_ComputerGraphics,代码行数:29,代码来源:ToolboxItem.cs
示例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);
}
}
开发者ID:4ux-nbIx,项目名称:gemini,代码行数:26,代码来源:ToolboxView.xaml.cs
示例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;
}
}
开发者ID:kilasuit,项目名称:PowerShell-CopyAsHtmlAddOn,代码行数:31,代码来源:CopyAsHtml.cs
示例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;
}
}
开发者ID:jgkim999,项目名称:WpfExample,代码行数:28,代码来源:ToolboxItem.cs
示例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
{
}
}
}
开发者ID:ychost,项目名称:PowerControlSimulation,代码行数:32,代码来源:CableKitsFactory.xaml.cs
示例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);
}
开发者ID:fatmingwang,项目名称:FM79979,代码行数:25,代码来源:NodeCandidates.xaml.cs
示例15: GetDataObject
public virtual DataObject GetDataObject(UIElement draggedElt)
{
string serializedElt = XamlWriter.Save(draggedElt);
DataObject obj = new DataObject();
obj.SetData(supportedFormat,serializedElt);
return obj;
}
开发者ID:atombender,项目名称:learning,代码行数:7,代码来源:DragSourceBase.cs
示例16: BuildDesktopInternetShortcutDragger
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;
}
开发者ID:nickhodge,项目名称:MahTweets.LawrenceHargrave,代码行数:26,代码来源:Dragger.cs
示例17: CopyToClipboard
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();
}
开发者ID:ClemensT,项目名称:WPF-Samples,代码行数:32,代码来源:MainWindow.cs
示例18: StartDrag
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;
}
开发者ID:ststeiger,项目名称:BstarDemo,代码行数:7,代码来源:MainWindow.xaml.cs
示例19: ToClipboard
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);
}
开发者ID:nikitadev,项目名称:DomainSetBidsApplication,代码行数:30,代码来源:FrameworkElement.extensions.cs
示例20: Flush
public void Flush()
{
if (_data != null)
{
Clipboard.SetDataObject(_data, true);
_data = null;
}
}
开发者ID:retailcoder,项目名称:Rubberduck,代码行数:8,代码来源:ClipboardWriter.cs
注:本文中的System.Windows.DataObject类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论