本文整理汇总了C#中IDataObject.GetDataPresent方法的典型用法代码示例。如果您正苦于以下问题:C# IDataObject.GetDataPresent方法的具体用法?C# IDataObject.GetDataPresent怎么用?C# IDataObject.GetDataPresent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataObject
的用法示例。
在下文中一共展示了IDataObject.GetDataPresent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendData
public void AppendData(ref IDataObject data, MouseEventArgs e)
{
if (!(this.list.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is ListBox)
&& !(this.list.InputHitTest(e.GetPosition(e.OriginalSource as UIElement)) is ScrollViewer)
&& !(e.OriginalSource is Thumb))
{
object o = this.list.SelectedItem;
// This is cheating .. just for an example's sake..
Debug.Assert(!data.GetDataPresent(DataFormats.Text));
if (o.GetType() == typeof(XmlElement))
{
data.SetData(DataFormats.Text, ((XmlElement)o).OuterXml);
}
else
{
data.SetData(DataFormats.Text, o.ToString());
}
Debug.Assert(!data.GetDataPresent(o.GetType().ToString()));
data.SetData(o.GetType().ToString(), o);
}
else
{
data = null;
}
}
示例2: CanConvertFrom
public static bool CanConvertFrom(IDataObject data)
{
if (data == null)
return false;
if (data.GetDataPresent(typeof(WordListEntries)) || data.GetDataPresent(typeof(TranslationPair[])))
return true;
var r = FromDelimitedText(GetText(data));
return r != null && r.Items.Count > 0;
}
示例3: IsValidDataObject
public bool IsValidDataObject(IDataObject obj)
{
bool result = false;
var elt = (FrameworkElement)this.TargetUI;
var storeItemVM = elt.DataContext as StoreItemViewModelBase;
//var channelVM = elt.DataContext as ChannelViewModel;
if (storeItemVM != null)
{
if (obj.GetDataPresent(typeof(StoreItemViewModelBase[])))
{
var data = (StoreItemViewModelBase[])obj.GetData(typeof(StoreItemViewModelBase[]));
result = data != null && data.Length > 0;
//.Any(droppedStoreItemVM => !channelListVM.Contains(droppedChannelVM));
}
}
//else if (channelVM != null)
//{
// if (obj.GetDataPresent(typeof(ChannelViewModel[])))
// {
// var data = (ChannelViewModel[])obj.GetData(typeof(ChannelViewModel[]));
// result = data
// .Any(droppedChannelVM => channelVM != droppedChannelVM);
// }
//}
return result;
}
示例4: DataObjectPastingEventArgs
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------
#region Constructors
/// <summary>
/// Creates a DataObjectPastingEvent.
/// This object created by editors executing a Copy/Paste
/// and Drag/Drop comands.
/// </summary>
/// <param name="dataObject">
/// DataObject extracted from the Clipboard and intended
/// for using in pasting.
/// </param>
/// <param name="isDragDrop">
/// A flag indicating whether this operation is part of drag/drop.
/// Pasting event is fired on drop.
/// </param>
/// <param name="formatToApply">
/// String identifying a format an editor has choosen
/// as a candidate for applying in Paste operation.
/// An application can change this choice after inspecting
/// the content of data object.
/// </param>
public DataObjectPastingEventArgs(IDataObject dataObject, bool isDragDrop, string formatToApply) //
: base(System.Windows.DataObject.PastingEvent, isDragDrop)
{
if (dataObject == null)
{
throw new ArgumentNullException("dataObject");
}
if (formatToApply == null)
{
throw new ArgumentNullException("formatToApply");
}
if (formatToApply == string.Empty)
{
throw new ArgumentException(SR.Get(SRID.DataObject_EmptyFormatNotAllowed));
}
if (!dataObject.GetDataPresent(formatToApply))
{
throw new ArgumentException(SR.Get(SRID.DataObject_DataFormatNotPresentOnDataObject, formatToApply));
}
_originalDataObject = dataObject;
_dataObject = dataObject;
_formatToApply = formatToApply;
}
示例5: GetNodesFromDataObject
public static OutlinerNode[] GetNodesFromDataObject(IDataObject dragData)
{
if (dragData.GetDataPresent(typeof(OutlinerNode[])))
return (OutlinerNode[])dragData.GetData(typeof(OutlinerNode[]));
else
return null;
}
示例6: SupportsDataObject
protected override bool SupportsDataObject(IServiceProvider serviceProvider, IDataObject dataObject)
{
if (!base.SupportsDataObject(serviceProvider, dataObject))
{
return dataObject.GetDataPresent(CodeWizard.CodeWizardDataFormat);
}
return true;
}
示例7: IsValidDataObject
public bool IsValidDataObject(IDataObject Object, Point dropPoint)
{
ProfileExplorerTreeItem dropTarget = GetExplorerTreeItem(_targetTreeView, dropPoint);
if (dropTarget != null)
{
if (Object.GetDataPresent("Helios.Trigger") && dropTarget.ItemType.HasFlag(ProfileExplorerTreeItemType.Action))
{
return true;
}
if (Object.GetDataPresent("Helios.Action") && dropTarget.ItemType.HasFlag(ProfileExplorerTreeItemType.Trigger))
{
return true;
}
}
return false;
}
示例8: API_ResultItemDropEvent
void API_ResultItemDropEvent(Result result, IDataObject dropObject, DragEventArgs e)
{
if (dropObject.GetDataPresent(DataFormats.FileDrop))
{
HanldeFilesDrop(result, dropObject);
}
e.Handled = true;
}
示例9: PasteContentData
internal static bool PasteContentData(InputBox inputBox, IDataObject iDataObject)
{
TextData data = TryGetText(iDataObject);
if (!data.ContainsData)
{
if (iDataObject.GetDataPresent(DataFormats.Bitmap, true))
{
inputBox.Paste(iDataObject);
return true;
}
return false;
}
inputBox.TempFlowDocument.Blocks.Clear();
TextRange range = null;
if (data.Format == BamaDataFormat)
{
object obj2 = XamlReader.Parse(data.Data);
if (obj2 is Block)
{
inputBox.TempFlowDocument.Blocks.Add(obj2 as Block);
}
else if (obj2 is Inline)
{
Span span = new Span(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd)
{
Inlines = { obj2 as Span }
};
}
range = new TextRange(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd);
range.ClearAllProperties();
inputBox.Selection.Text = "";
Span newspan = new Span(inputBox.Selection.Start, inputBox.Selection.End);
ReplaceControls.AddBlocksToSpan(inputBox.TempFlowDocument, newspan);
inputBox.CaretPosition = newspan.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
}
else
{
range = new TextRange(inputBox.TempFlowDocument.ContentStart, inputBox.TempFlowDocument.ContentEnd);
using (MemoryStream stream = new MemoryStream())
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(data.Data);
writer.Flush();
stream.Position = 0L;
range.Load(stream, data.Format);
}
}
range.ClearAllProperties();
inputBox.Selection.Text = "";
Span span3 = new Span(inputBox.Selection.Start, inputBox.Selection.End);
ReplaceControls.AddBlocksToSpan(inputBox.TempFlowDocument, span3);
inputBox.CaretPosition = span3.ElementEnd.GetInsertionPosition(LogicalDirection.Forward);
}
inputBox.TempFlowDocument.Blocks.Clear();
return true;
}
示例10: GetText
private string GetText(IDataObject dataObject)
{
if(dataObject.GetDataPresent(DataFormats.UnicodeText))
{
var text = dataObject.GetData(DataFormats.UnicodeText);
return text?.ToString() ?? "";
}
return "";
}
示例11: GetList
/// <summary>
/// Gets the list of <see cref="FileDrop"/> from the specified <see cref="IDataObject"/>. Includes objects dragged from Explorer and Outlook.
/// </summary>
/// <param name="data">The <see cref="IDataObject"/>.</param>
/// <returns>The list of <see cref="FileDrop"/> from the specified <see cref="IDataObject"/>.</returns>
public static List<FileDrop> GetList(IDataObject data)
{
List<FileDrop> list = new List<FileDrop>();
if (data != null)
{
if (data.GetDataPresent("FileDrop"))
{
string[] fileNames = data.GetData("FileDrop") as string[];
if (fileNames != null && fileNames.Length > 0)
{
foreach (string fileName in fileNames)
{
list.Add(new FileDrop(fileName));
}
}
}
else if (data.GetDataPresent("FileGroupDescriptor"))
{
Stream stream = (Stream)data.GetData("FileGroupDescriptor");
byte[] fileGroupDescriptor = new byte[512];
stream.Read(fileGroupDescriptor, 0, 512);
// build the filename from the FileGroupDescriptor block
StringBuilder fileName = new StringBuilder();
for (int i = 76; fileGroupDescriptor[i] != 0; i++)
{
fileName.Append(Convert.ToChar(fileGroupDescriptor[i]));
}
stream.Close();
MemoryStream ms = (MemoryStream)data.GetData("FileContents", true);
byte[] fileBytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(fileBytes, 0, (int)ms.Length);
list.Add(new FileDrop(fileName.ToString(), fileBytes));
}
}
return list;
}
示例12: GetTextFromDataObject
protected override string GetTextFromDataObject(IDataObject dataObject, IServiceProvider serviceProvider)
{
if (dataObject.GetDataPresent(CodeWizard.CodeWizardDataFormat))
{
string codeWizardTypeName = dataObject.GetData(CodeWizard.CodeWizardDataFormat).ToString();
CodeWizardHost host = new CodeWizardHost(serviceProvider);
return host.RunCodeWizard(codeWizardTypeName, this.CodeDomProvider);
}
return base.GetTextFromDataObject(dataObject, serviceProvider);
}
示例13: GetTextFromDataObject
protected override string GetTextFromDataObject(IDataObject dataObject, IServiceProvider serviceProvider)
{
if (dataObject.GetDataPresent(DataFormats.Text))
{
return base.GetTextFromDataObject(dataObject, serviceProvider);
}
if (!dataObject.GetDataPresent(DataFormats.Html))
{
return string.Empty;
}
string str = dataObject.GetData(DataFormats.Html).ToString();
int index = str.IndexOf("<!--StartFragment-->");
int num2 = str.LastIndexOf("<!--EndFragment-->");
if ((index != -1) && (num2 != -1))
{
index += 20;
str = str.Substring(index, num2 - index);
}
return str;
}
示例14: Create
/// <summary>
/// Creates a URLData based upon an IDataObject
/// </summary>
/// <param name="iDataObject">The IDataObject from which to create the URLData</param>
/// <returns>The URLData, null if no URLData could be created</returns>
public static URLData Create(IDataObject iDataObject)
{
// WinLive Bug 198371: Look at rolling the fix for WinLive 182698 into the OleDataObjectHelper.GetDataPresentSafe method
// For now, we keep the changes targeted.
bool canGetDataPresentDirectlyFromIDataObject = false;
try
{
canGetDataPresentDirectlyFromIDataObject = iDataObject.GetDataPresent(DataFormatsEx.URLFormat) &&
iDataObject.GetDataPresent(DataFormatsEx.FileGroupDescriptorWFormat);
}
catch (Exception e)
{
Debug.Fail(e.ToString());
}
// Validate required format
// WinLive Bug 182698: Assert when pasting a hyperlink from IE
if (canGetDataPresentDirectlyFromIDataObject &&
OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.URLFormat) &&
OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormatsEx.FileGroupDescriptorWFormat))
return new URLData(iDataObject);
else
{
//check to see if the dataObject contains a single .url file,
//if so, create the URLData from that.
FileData fileData = FileData.Create(iDataObject);
if (fileData != null && fileData.Files.Length == 1)
{
string filePath = fileData.Files[0].ContentsPath;
if (PathHelper.IsPathUrlFile(filePath))
{
URLData urlData = new URLData(iDataObject, UrlHelper.GetUrlFromShortCutFile(filePath), Path.GetFileNameWithoutExtension(filePath));
urlData.DateCreated = File.GetCreationTime(filePath);
urlData.DateModified = File.GetLastWriteTime(filePath);
return urlData;
}
}
}
return null;
}
示例15: GetFromWindowsClipboard
/// <summary>
///
/// </summary>
/// <returns>null if data isn't in this format</returns>
public static SerializableUniverse GetFromWindowsClipboard(IDataObject dataBlob)
{
SerializableUniverse retVal = null;
if (dataBlob.GetDataPresent(typeof(SerializableUniverse)))
{
// someday, we might worry about this
// System.Runtime.InteropServices.COMException
// but not now
retVal = (SerializableUniverse)dataBlob.GetData(typeof(SerializableUniverse));
}
return retVal;
}