2011-12-21 77 views
0

我運行的是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); 
     } 

    } 
} 
+0

http://social.msdn.microsoft.com/Forums/en-US/windowswic/thread/fdfff143-c1ae-41cd-bbeb-8ff6c1c879ec有一些線索。 – 2011-12-21 05:40:54

+0

請不要在「Visual Studio .NET:」等標題前添加前綴。那是什麼標籤用於[所以]。 – 2011-12-21 21:47:24

回答

1

首先,即使方法是靜態的,也不能將方法與類分開。嘗試做這樣的事情:

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); 
      } 
     } 
    } 
} 
+0

.NET版本4. WindowsBase已被添加併發生相同的問題。 – 2011-12-21 15:04:28

+0

我試圖剪切並粘貼我的代碼。但是本網站上的格式規則本身就是一種編程語言。它不會讓我發佈代碼,因爲它不會讓我剪切和粘貼。我可以將代碼發送給你。這可以嗎? – 2011-12-21 15:26:30

+0

沒問題,等你的代碼。我已經安裝了裝有XP SP3的機器,所以很容易檢查你的代碼有什麼問題。 – Kath 2011-12-21 18:21:50

相關問題