“使用System.Windows.Media”即使PresentationCore.dll被引用也无法识别
我运行的是Windows XP Service Pack 3. Visual Studio 2010. C#项目。“使用System.Windows.Media”即使PresentationCore.dll被引用也无法识别
我在类项目中包含了“Using System.Windows.Media”和“Using System.Windows.Media.Imaging”。我还添加了PresentationCore.dll参考。这是在解决方案窗口完成的。
所谓的“智能感知”是对来自这些命名空间的所有功能进行重新排列。我没有做任何修复。为什么编译器不能识别PresentationCore参考?
我需要解决这个问题FAST。
谢谢任何善意帮助我的人。
using System.Windows
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace TextEditor
{
public partial class App : Application
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionOccurred;
}
private static void UnhandledExceptionOccurred(object sender, UnhandledExceptionEventArgs e)
{
Window win = Current.MainWindow;
RenderTargetBitmap bmp = new RenderTargetBitmap((int) win.Width, (int) win.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(win);
string errorPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorReports");
if(!Directory.Exists(errorPath))
Directory.CreateDirectory(errorPath);
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
string filePath = Path.Combine(errorPath, string.Format("{0:MMddyyyyhhmmss}.png", DateTime.Now));
using(Stream stream = File.Create(filePath))
{
encoder.Save(stream);
}
}
}
首先,即使方法是静态的,也不能将方法与类分开。尝试做这样的事情:
namespace TestProject
{
public partial class App : Application
{
public void Init()
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionOccurred;
}
private static void UnhandledExceptionOccurred(object sender, UnhandledExceptionEventArgs e)
{
Window win = Current.MainWindow;
RenderTargetBitmap bmp = new RenderTargetBitmap((int)win.Width, (int)win.Height, 96, 96, PixelFormats.Pbgra32);
bmp.Render(win);
string errorPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorReports");
if (!Directory.Exists(errorPath))
Directory.CreateDirectory(errorPath);
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
string filePath = Path.Combine(errorPath, string.Format("{0:MMddyyyyhhmmss}.png", DateTime.Now));
using (Stream stream = File.Create(filePath))
{
encoder.Save(stream);
}
}
}
}
.NET版本4. WindowsBase已被添加并发生相同的问题。 – 2011-12-21 15:04:28
我试图剪切并粘贴我的代码。但是本网站上的格式规则本身就是一种编程语言。它不会让我发布代码,因为它不会让我剪切和粘贴。我可以将代码发送给你。这可以吗? – 2011-12-21 15:26:30
没问题,等你的代码。我已经安装了装有XP SP3的机器,所以很容易检查你的代码有什么问题。 – Kath 2011-12-21 18:21:50
http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec有一些线索。 – 2011-12-21 05:40:54
请不要在“Visual Studio .NET:”等标题前添加前缀。那是什么标签用于[所以]。 – 2011-12-21 21:47:24