本文整理汇总了C#中System.Windows.DataObject.SetData方法的典型用法代码示例。如果您正苦于以下问题:C# DataObject.SetData方法的具体用法?C# DataObject.SetData怎么用?C# DataObject.SetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.DataObject
的用法示例。
在下文中一共展示了DataObject.SetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: CopyChartToClipboard
// ********************************************************************
// Public Methods
// ********************************************************************
#region Public Methods
/// <summary>
/// Copies the plotToCopy as a bitmap to the clipboard, and copies the
/// chartControl to the clipboard as tab separated values.
/// </summary>
/// <param name="plotToCopy"></param>
/// <param name="chartControl"></param>
/// <param name="width">Width of the bitmap to be created</param>
/// <param name="height">Height of the bitmap to be created</param>
public static void CopyChartToClipboard(FrameworkElement plotToCopy, XYLineChart chartControl, double width, double height)
{
Bitmap bitmap = CopyFrameworkElementToBitmap(plotToCopy, width, height);
string text = ConvertChartToSpreadsheetText(chartControl, '\t');
MemoryStream csv = new MemoryStream(Encoding.UTF8.GetBytes(ConvertChartToSpreadsheetText(chartControl, ',')));
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.Bitmap, bitmap);
dataObject.SetData(DataFormats.Text, text);
dataObject.SetData(DataFormats.CommaSeparatedValue, csv);
Clipboard.SetDataObject(dataObject);
}
示例4: OnMouseMove
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton == MouseButtonState.Pressed)
{
DataObject data = new DataObject();
data.SetData("Item", MainWindow.player.Inventory[Index]);
data.SetData("Object", this);
DragDrop.DoDragDrop(this, data, DragDropEffects.Move);
}
}
示例5: CopyChartToClipboard
// ********************************************************************
// Public Methods
// ********************************************************************
#region Public Methods
public static void CopyChartToClipboard(FrameworkElement plotToCopy, ChartControl chartControl, double width, double height) {
plotToCopy = plotToCopy ?? chartControl;
System.Drawing.Bitmap bitmap = CopyFrameworkElementToBitmap(plotToCopy, width, height);
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.Bitmap, bitmap);
if(chartControl != null) {
string text = ChartUtilities.ConvertChartToSpreadsheetText(chartControl, '\t');
MemoryStream csv = new MemoryStream(Encoding.UTF8.GetBytes(ChartUtilities.ConvertChartToSpreadsheetText(chartControl, ',')));
dataObject.SetData(DataFormats.Text, text);
dataObject.SetData(DataFormats.CommaSeparatedValue, csv);
}
Clipboard.SetDataObject(dataObject);
}
示例6: OnMouseMove
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.LeftButton == MouseButtonState.Pressed)
{
DataObject data = new DataObject();
data.SetData(DataFormats.StringFormat, circleUI.Fill.ToString());
data.SetData("Double", circleUI.Height);
data.SetData("Object", this);
DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move);
}
}
示例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: 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;
}
示例9: 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);
}
示例10: GetDataObject
public virtual DataObject GetDataObject(UIElement draggedElt)
{
string serializedElt = XamlWriter.Save(draggedElt);
DataObject obj = new DataObject();
obj.SetData(supportedFormat,serializedElt);
return obj;
}
示例11: 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;
}
示例12: List_MouseMove
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);
}
}
示例13: GetDataObject
protected override IDataObject GetDataObject(SharpTreeNode[] nodes)
{
string[] data = nodes
.OfType<XamlOutlineNode>()
.Select(item => item.GetMarkupText())
.ToArray();
var dataObject = new DataObject();
dataObject.SetData(typeof(string[]), data);
return dataObject;
}
示例14: GetDataObject
public DataObject GetDataObject(UIElement draggedElement, Point location)
{
DataObject data = new DataObject();
ToolboxItem item = GetToolboxItem(draggedElement);
if (item != null)
{
item.IsBeingDragged = true;
data.SetData("Helios.Visual", item.CreateControl());
}
return data;
}
示例15: SetClipboardData
/// <summary>
/// Places the provided data on the clipboard overriding what is currently in the clipboard.
/// </summary>
/// <param name="isSingleLine">Indicates whether a single line was automatically cut/copied by
/// the editor. If <c>true</c> the clipboard contents are tagged with a special moniker.</param>
public static void SetClipboardData(string html, string rtf, string unicode, bool isSingleLine, bool isBoxCopy)
{
DataObject data = new DataObject();
if (unicode != null)
{
data.SetText(unicode, TextDataFormat.UnicodeText);
data.SetText(unicode, TextDataFormat.Text);
}
if (html != null)
{
data.SetText(GetHtmlForClipboard(html), TextDataFormat.Html);
}
if (rtf != null)
{
data.SetText(rtf, TextDataFormat.Rtf);
}
if (isSingleLine)
{
data.SetData(ClipboardLineBasedCutCopyTag, new object());
}
if (isBoxCopy)
{
data.SetData(BoxSelectionCutCopyTag, new object());
}
try
{
// Use delay rendering to set the data in the clipboard to prevent 2 clipboard change
// notifications to clipboard change listeners.
Clipboard.SetDataObject(data, false);
}
catch (System.Runtime.InteropServices.ExternalException)
{
}
}