本文整理汇总了C#中IDataObject类的典型用法代码示例。如果您正苦于以下问题:C# IDataObject类的具体用法?C# IDataObject怎么用?C# IDataObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDataObject类属于命名空间,在下文中一共展示了IDataObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemDropped
public override bool ItemDropped(IDataObject dragData)
{
if (IsValidDropTarget(dragData))
{
OutlinerNode[] droppedNodes = GetNodesFromDataObject(dragData);
Int32[] droppedNodeHandles = new Int32[droppedNodes.Length];
Tree.BeginTimedUpdate();
Tree.BeginTimedSort();
Int32 i = 0;
foreach (OutlinerNode n in droppedNodes)
{
//Tree.LinkObject((OutlinerObject)n, Data.Handle, false, false);
droppedNodeHandles[i] = ((OutlinerObject)n).Handle;
i++;
}
//Tree.RaiseObjectLinkedEvent(new NodeLinkedEventArgs(droppedNodeHandles, Data.Handle));
Tree.RaiseObjectAddedToContainerEvent(new NodeGroupedEventArgs(droppedNodeHandles, Data.Handle, true, false));
return true;
}
return false;
}
示例2: 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);
}
}
示例3: GetNodesFromDataObject
public static OutlinerNode[] GetNodesFromDataObject(IDataObject dragData)
{
if (dragData.GetDataPresent(typeof(OutlinerNode[])))
return (OutlinerNode[])dragData.GetData(typeof(OutlinerNode[]));
else
return null;
}
示例4: GetDragDropEffect
public override DragDropEffects GetDragDropEffect(IDataObject dragData)
{
if (IsValidDropTarget(dragData))
return DragDropEffects.Copy;
else
return Outliner.TreeView.DragDropEffectsNone;
}
示例5: 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;
}
示例6: 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;
}
}
示例7: 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);
}
示例8: Format
public string Format(IDataObject obj)
{
if (obj == null) return string.Empty;
var cls = _resolver.GetObjectClass(obj.Context.GetInterfaceType(obj));
var allProps = cls.GetAllProperties();
var result = new StringBuilder();
foreach (var prop in allProps.OfType<StringProperty>().OrderBy(p => p.Name))
{
var txtVal = obj.GetPropertyValue<string>(prop.Name);
if (!string.IsNullOrWhiteSpace(txtVal))
{
result.AppendLine(txtVal);
}
}
foreach (var prop in allProps.OfType<EnumerationProperty>().OrderBy(p => p.Name))
{
var enumVal = obj.GetPropertyValue<int>(prop.Name);
var txtVal = prop.Enumeration.GetLabelByValue(enumVal);
if (!string.IsNullOrWhiteSpace(txtVal))
{
result.AppendLine(txtVal);
}
}
return result.ToString();
}
示例9: CheckRequiredProperties
private static void CheckRequiredProperties(IDataObject dataObj, ref DataObjectOperationResult result)
{
//Get Required Properties
var requiredProperties = dataObj.GetType()
.GetProperties()
.Where(x => Attribute.IsDefined(x, typeof(RequiredValueAttribute)));
//Check to Ensure Required Properties are not Null or empty
foreach (var reqProp in requiredProperties)
{
var prop = dataObj.GetType().GetProperty(reqProp.Name);
var propValue = prop.GetValue(dataObj, null);
bool isNull = false;
switch (prop.PropertyType.Name.ToLower())
{
case "string":
isNull = string.IsNullOrEmpty((string)propValue);
break;
default:
isNull = propValue == null;
break;
}
if (isNull)
{
RequiredValueAttribute reqAttrib = (RequiredValueAttribute)(prop.GetCustomAttributes(typeof(RequiredValueAttribute), false)[0]);
//var reqAttrib = prop.GetCustomAttribute<RequiredValueAttribute>();
result.Message = "A Required Value is Missing";
result.ErrorMessages.Add(reqProp.Name, reqAttrib.ErrorMessage);
result.Success = false;
}
}
}
示例10: 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;
}
}
示例11: 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;
}
示例12: CreateFrom
/// <summary>
/// Create an OleDataObject from a .NET IDataObject.
/// </summary>
/// <param name="ido">IDataObject to extract OleDataObject from</param>
/// <returns>A new instance of OleDataObject mapped to the inner
/// OleDataObject of the specified IDataObject or null if unable
/// to extract OleDataObject from IDataObject</returns>
public static OleDataObject CreateFrom(IDataObject ido)
{
// initialize OleDataObject
OleDataObject oleDataObject = new OleDataObject();
// attempt to convert to concrete DataObject class
DataObject dataObject = ido as DataObject;
if (dataObject == null)
{
return null;
}
// To extract an OleDataObject from a DataObject, we first need to
// get the "innerData" field of the DataObject. This field is of type
// System.Windows.Forms.UnsafeNativeMethods.OleConverter. Next, we
// need to get the "innerData" field of the OleConverter, which is of
// type System.Windows.Forms.UnsafeNativeMethods.IOleDataObject
const string INNER_DATA_FIELD = "innerData";
object innerData = oleDataObject.GetField(dataObject, INNER_DATA_FIELD);
object innerInnerData = oleDataObject.GetField(innerData, INNER_DATA_FIELD);
// attempt to convert the 'private' ole data object contained in
// innerData into an instance of our locally defined IOleDataObject
oleDataObject.m_dataObject = innerInnerData as IOleDataObject;
if (oleDataObject.m_dataObject != null)
{
return oleDataObject;
}
else
{
return null;
}
}
示例13: 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;
}
示例14: 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;
}
示例15: DoCopy
protected override void DoCopy(IDataObject dataObject)
{
// samgeo - Presharp issue
// Presharp gives a warning when local IDisposable variables are not closed
// in this case, we can't call Dispose since it will also close the underlying stream
// which needs to be open for consumers to read
#pragma warning disable 1634, 1691
#pragma warning disable 6518
// Save the data in the data object.
MemoryStream stream = new MemoryStream();
Strokes.Save(stream);
stream.Position = 0;
(new UIPermission(UIPermissionClipboard.AllClipboard)).Assert();//BlessedAssert
try
{
dataObject.SetData(StrokeCollection.InkSerializedFormat, stream);
}
finally
{
UIPermission.RevertAssert();
}
#pragma warning restore 6518
#pragma warning restore 1634, 1691
}