首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即使引用了PresentationCore.dll,也无法识别"using System.Windows.Media“

即使引用了PresentationCore.dll,也无法识别"using System.Windows.Media“
EN

Stack Overflow用户
提问于 2011-12-21 13:36:14
回答 1查看 3.2K关注 0票数 0

我运行的是Windows XP Service Pack 3. Visual Studio 2010。C#项目。

我在一个类项目中包含了“使用System.Windows.Media”和“使用System.Windows.Media.Imaging”。我还添加了PresentationCore.dll引用。这是在解决方案窗口中完成的。

所谓的“智能感知”对来自这些命名空间的所有函数进行了红线标记。无论我做什么都无法修复它。为什么编译器无法识别PresentationCore引用?

我需要一个快速解决这个问题的方案。

感谢所有好心帮助我的人。

代码语言:javascript
复制
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);
        }

    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-21 13:48:14

首先,即使方法是静态的,也不能将方法从类中分离出来。试着这样做:

代码语言:javascript
复制
    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);
            }
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8585510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档