本文整理汇总了C#中IDataObject.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# IDataObject.GetData方法的具体用法?C# IDataObject.GetData怎么用?C# IDataObject.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataObject
的用法示例。
在下文中一共展示了IDataObject.GetData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LimitDragDropOptions
public bool LimitDragDropOptions(IDataObject data)
{
var formats = data.GetFormats();
if(!formats.Any())
{
return true;
}
var modelItemString = formats.FirstOrDefault(s => s.IndexOf("ModelItemsFormat", StringComparison.Ordinal) >= 0);
if(!String.IsNullOrEmpty(modelItemString))
{
var innnerObjectData = data.GetData(modelItemString);
var modelList = innnerObjectData as List<ModelItem>;
if(modelList != null && modelList.Count > 1)
{
if(modelList.FirstOrDefault(c => c.ItemType == typeof(FlowDecision) || c.ItemType == typeof(FlowSwitch<string>)) != null)
{
return false;
}
}
}
modelItemString = formats.FirstOrDefault(s => s.IndexOf("ModelItemFormat", StringComparison.Ordinal) >= 0);
if(String.IsNullOrEmpty(modelItemString))
{
modelItemString = formats.FirstOrDefault(s => s.IndexOf("WorkflowItemTypeNameFormat", StringComparison.Ordinal) >= 0);
if(String.IsNullOrEmpty(modelItemString))
{
return true;
}
}
var objectData = data.GetData(modelItemString);
return DropPointOnDragEnter(objectData);
}
示例2: GetImageUrl
static string GetImageUrl(IDataObject data)
{
var fileDrops = (string[])data.GetData(DataFormats.FileDrop);
if (fileDrops?.Length >= 1) return fileDrops[0];
var text = (string)data.GetData(DataFormats.UnicodeText);
return text;
}
示例3: GetDataFilePath
public static string GetDataFilePath(IDataObject data) {
string fileName = null;
string[] fileNames = (string[]) data.GetData(DataFormats.FileDrop);
if ( (fileNames != null) && (fileNames.Length > 0) ) {
fileName = fileNames[0];
} else {
fileName = (string) data.GetData("UnicodeText");
}
return fileName;
}
示例4: GetNodesFromDataObject
public static OutlinerNode[] GetNodesFromDataObject(IDataObject dragData)
{
if (dragData.GetDataPresent(typeof(OutlinerNode[])))
return (OutlinerNode[])dragData.GetData(typeof(OutlinerNode[]));
else
return null;
}
示例5: ProcessFileNames
private void ProcessFileNames(IDataObject obj, string format)
{
try
{
var fileNames = obj.GetData(format, true) as string[];
var fileName = fileNames.FirstOrDefault();
if (fileName != null)
{
var file = File.ReadAllBytes(fileName);
using (var ms = new System.IO.MemoryStream(file))
{
var image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad; // here
image.StreamSource = ms;
image.EndInit();
ViewModel.Model.SquareDraft = image;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
示例6: DoPaste
// Retrieves the text from the IDataObject instance.
// Then create a textbox with the text data.
protected override void DoPaste(IDataObject dataObject)
{
ElementList = new List<UIElement>();
// Get the string from the data object.
string text = dataObject.GetData(DataFormats.UnicodeText, true) as string;
if ( String.IsNullOrEmpty(text) )
{
// OemText can be retrieved as CF_TEXT.
text = dataObject.GetData(DataFormats.Text, true) as string;
}
if ( !String.IsNullOrEmpty(text) )
{
// Now, create a text box and set the text to it.
TextBox textBox = new TextBox();
textBox.Text = text;
textBox.TextWrapping = TextWrapping.Wrap;
// Add the textbox to the internal array list.
ElementList.Add(textBox);
}
}
示例7: Create
/// <summary>
/// Attempts to create a new HTMLData. This can return null if the DataObject
/// couldn't be created based upon the IDataObject.
/// </summary>
/// <param name="iDataObject">The IDataObject from which to create the HTML Data Object</param>
/// <returns>The HTMLData, null if it couldn't be created.</returns>
public static HTMLData Create(IDataObject iDataObject)
{
string[] loser = iDataObject.GetFormats();
if (OleDataObjectHelper.GetDataPresentSafe(iDataObject, DataFormats.Html))
{
try
{
HTMLData data = new HTMLData(iDataObject, null);
return string.IsNullOrEmpty(data.HTML) ? null : data;
}
catch (FormatException)
{
// EML files with HTML inside of them report that they are HTML
// However, when we try to read the format, we have problems reading it
// So we will skip loading html that we cannot load
return null;
}
}
else if (HtmlDocumentClassFormatPresent(iDataObject))
{
return new HTMLData(iDataObject, (IHTMLDocument2)iDataObject.GetData(typeof(HTMLDocumentClass)));
}
else
return null;
}
示例8: Drop
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
{
try {
string insertText = (data.GetData(typeof(string[])) as string[])
.Aggregate((text, part) => text += part);
ITextAnchor marker;
int length = 0;
if (index == this.Children.Count) {
if (index == 0)
marker = null;
else
marker = (this.Children[index - 1] as XamlOutlineNode).EndMarker;
if (marker == null) {
marker = this.EndMarker;
length = -1; // move backwards
} else {
length = 2 + (this.Children[index - 1] as XamlOutlineNode).elementName.Length;
}
} else
marker = (this.Children[index] as XamlOutlineNode).Marker;
int offset = marker.Offset + length;
Editor.Document.Insert(offset, insertText);
} catch (Exception ex) {
throw ex;
}
}
示例9: 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;
}
示例10: CloneClipboard
private IDataObject CloneClipboard(IDataObject obj)
{
if (obj == null)
return null;
string[] formats = obj.GetFormats();
if (formats.Length == 0)
return null;
IDataObject newObj = new DataObject();
foreach (string format in formats)
{
if (format.Contains("EnhancedMetafile")) //Ignore this. Cannot be processed in .NET
continue;
object o = obj.GetData(format);
if (o != null)
{
newObj.SetData(o);
}
}
return newObj;
}
示例11: ExtractElement
public virtual UIElement ExtractElement(IDataObject obj)
{
string xamlString = obj.GetData(supportedFormat) as string;
XmlReader reader = XmlReader.Create(new StringReader(xamlString));
UIElement elt = XamlReader.Load(reader) as UIElement;
return elt;
}
示例12: CanDrop
public override DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
{
var paths = data.GetData(typeof(string[])) as string[];
if (paths != null) {
return requestedEffect == DropEffect.Link ? DropEffect.Move : requestedEffect;
}
return DropEffect.None;
}
示例13: OnDropCompleted
public void OnDropCompleted(IDataObject obj, Point dropPoint)
{
string serializedObject = obj.GetData(SupportedFormat.Name) as string;
XmlReader reader = XmlReader.Create(new StringReader(serializedObject));
UIElement elt = XamlReader.Load(reader) as UIElement;
(TargetUI as Panel).Children.Add(elt);
}
示例14: CanDropDataObject
protected virtual bool CanDropDataObject(IDataObject dataObj)
{
if (dataObj != null)
{
if (dataObj is ComponentDataObjectWrapper)
{
object[] draggingObjects = this.GetDraggingObjects(dataObj, true);
if (draggingObjects == null)
{
return false;
}
bool flag = true;
for (int i = 0; flag && (i < draggingObjects.Length); i++)
{
flag = (flag && (draggingObjects[i] is IComponent)) && this.client.IsDropOk((IComponent) draggingObjects[i]);
}
return flag;
}
try
{
object data = dataObj.GetData(DataFormat, false);
if (data == null)
{
return false;
}
IDesignerSerializationService service = (IDesignerSerializationService) this.GetService(typeof(IDesignerSerializationService));
if (service == null)
{
return false;
}
ICollection is2 = service.Deserialize(data);
if (is2.Count > 0)
{
bool flag2 = true;
foreach (object obj3 in is2)
{
if (obj3 is IComponent)
{
flag2 = flag2 && this.client.IsDropOk((IComponent) obj3);
if (!flag2)
{
return flag2;
}
}
}
return flag2;
}
}
catch (Exception exception)
{
if (System.Windows.Forms.ClientUtils.IsCriticalException(exception))
{
throw;
}
}
}
return false;
}
示例15: GetDropData
public object GetDropData(IDataObject obj)
{
string serializedObject = obj.GetData(SupportedFormat.Name) as string;
if (string.IsNullOrEmpty(serializedObject))
return null;
XmlReader reader = XmlReader.Create(new StringReader(serializedObject));
return XamlReader.Load(reader) as UIElement;
}