【发布时间】:2012-11-15 02:11:00
【问题描述】:
为什么System.Windows.Clipboard(PresentationCore.dll) 不友好
System.Windows.Thickness (PresentationFramework.dll) 但对 System.Windows.Point (WindowsBase.dll) 友好
using System;
namespace ConsoleApplication5 {
class Program {
/*
* Add references to
* WindowsBase.dll (Point)
* PresentationFramework.dll (Thickness)
* PresentationCore.dll (Clipboard)
*/
[STAThread]
static void Main(string[] args)
{
Test myTest = new Test();
System.Windows.Clipboard.SetData("myformat", myTest);
// OutOfMemoryException
Object myPastedTest = System.Windows.Clipboard.GetData("myformat");
}
}
[Serializable]
class Test
{
// COMMENT THE LINES BELLOW PresentationFramework TO WORK OK!
// PresentationFramework.dll
//public System.Windows.Thickness MyThickness { get; set; }
public System.Windows.Media.Brush MyBrush { get; set; }
// WindowsBase.dll
public System.Windows.Point MyPoint { get; set; }
}
}
【问题讨论】:
-
剪贴板上有多少数据?
-
This answer 可能会为您提供解决方案,但我无法告诉您为什么剪贴板讨厌某些对象而不讨厌其他对象。我认为它与对象是否可序列化有关