我运行的是Windows XP Service Pack 3. Visual Studio 2010。C#项目。
我在一个类项目中包含了“使用System.Windows.Media”和“使用System.Windows.Media.Imaging”。我还添加了PresentationCore.dll引用。这是在解决方案窗口中完成的。
所谓的“智能感知”对来自这些命名空间的所有函数进行了红线标记。无论我做什么都无法修复它。为什么编译器无法识别PresentationCore引用?
我需要一个快速解决这个问题的方案。
感谢所有好心帮助我的人。
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);
}
}
}发布于 2011-12-21 13:48:14
首先,即使方法是静态的,也不能将方法从类中分离出来。试着这样做:
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);
}
}
}
}https://stackoverflow.com/questions/8585510
复制相似问题