Hello,
I’d like to override the copy paste function to actualize my data-structure.
Then I made my own CommandHandler to override CopyToClipboard and PasteFromClipboard.
But I get the following error :
Une exception de première chance de type 'System.OutOfMemoryException' s'est produite dans PresentationCore.dll
System.OutOfMemoryException: Mémoire insuffisante pour continuer l'exécution du programme.
à System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
à System.Windows.DataObject.OleConverter.GetDataInner(FORMATETC& formatetc, STGMEDIUM& medium)
à System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
à System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
à System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
à System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
à System.Windows.DataObject.GetData(String format, Boolean autoConvert)
à System.Windows.Clipboard.GetDataInternal(String format)
à System.Windows.Clipboard.GetData(String format)
à Northwoods.GoXam.CommandHandler.PasteFromClipboard()
à SphinxV6.Concept.QDiagram.QD_CommandHandler.PasteFromClipboard() dans C:\dvlp\Project\WPF4\SphinxV6\Concept\QDiagram\Code\QD_DragSelectingTool.cs:ligne 78
à Northwoods.GoXam.CommandHandler.Paste()
I use GoWPF, v1.1.3.3.
To help you understanding, here’s my code :
public class QD_CommandHandler : CommandHandler
{
protected override void CopyToClipboard(IDataCollection coll)
{
base.CopyToClipboard(coll);
List<QD_Node> lForDelete = new List<QD_Node>();
IEnumerable<SphPart> oSphPart = null;
try
{
oSphPart = (IEnumerable<SphPart>)coll.Nodes.Where(n => ((QD_Node)n).QDCategory == QD_Node.ECategory.Part).Select(n => (SphPart)((QD_Node)n).Item);
}
catch { }
foreach (QD_Node oNode in coll.Nodes)
{
switch (oNode.QDCategory)
{
case QD_Node.ECategory.Note:
oNode.Note = (SphNote)oNode.Note.Clone();
break;
case QD_Node.ECategory.Restriction:
lForDelete.Add(oNode);
break;
default:
if (oSphPart != null && oNode.Item.GetParentParts().Intersect(oSphPart).Any() == false)
oNode.Item = oNode.Item.Clone();
break;
}
}
if (lForDelete.Count > 0)
{
MessageBox.Show("Les restrictions ne seront pas copiées.", "Restriction", MessageBoxButton.OK, MessageBoxImage.Information);
foreach (QD_Node oNode in lForDelete)
{
coll.RemoveNode(oNode);
}
}
List<QD_Link> lLinkForDelete = new List<QD_Link>();
foreach (QD_Link oLink in coll.Links)
{
if (oLink.QDCategory != QD_Link.ECategory.Belongs)
{
lLinkForDelete.Add(oLink);
}
}
if (lLinkForDelete.Count > 0)
{
foreach (QD_Link oLink in lLinkForDelete)
{
coll.RemoveLink(oLink);
}
}
}
protected override IDataCollection PasteFromClipboard()
{
IDataCollection oColl = base.PasteFromClipboard();
foreach (QD_Node oNode in oColl.Nodes)
{
switch (oNode.QDCategory)
{
case QD_Node.ECategory.Note:
Session.Survey.Notes.Add(oNode.Note);
break;
case QD_Node.ECategory.Restriction:
//TODO
break;
default:
Session.Survey.Items.Add(oNode.Item);
break;
}
}
return oColl;
}
}
Thanks for your help
Aurore