gpt4 book ai didi

c# - 剪贴板 + PresentationFramework = OutOfMemoryException?

转载 作者:行者123 更新时间:2023-11-30 14:34:46 25 4
gpt4 key购买 nike

为什么 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; }

}
}

最佳答案

Brush 类不可序列化并导致抛出 OutOfMemoryException(参见 http://www.grumpydev.com/2009/09/05/system-outofmemoryexception-gotcha-using-clipboard-getdata-in-wpf/)。您可以将测试类序列化为 XAML 并将其放到剪贴板上,有关信息,请参阅此链接:

How can i serialize xaml "Brush"?

关于c# - 剪贴板 + PresentationFramework = OutOfMemoryException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com