2009-10-02 129 views
6

我有一個Silverlight應用程序,我需要在Web項目中的System.Windows中使用Vector類。但VS抱怨System.Windows不存在。我嘗試添加引用,但它不在要添加的名稱空間列表中。在.NET選項卡中,它從System.Web.Services轉到System.Windows.Forms並完全跳過System.Windows。缺少System.Windows參考

真正奇怪的是System.Windows DOES存在於Silverlight項目的參考列表中。此外,我在這臺機器上安裝了另一個Silverlight應用程序,它具有完全相同的設置(兩個項目,一個Silverlight,一個Web),並且參考在那裏。

我看到有人在這裏有類似的問題,但沒有解決方案爲我工作。有沒有其他人經歷過這個?

回答

7

我找到了!您必須添加對WindowsBase的引用。

設置Silverlight應用程序的常用方法(我猜)是有兩個項目:一個用於Silverlight客戶端代碼,另一個用於服務器端aspx頁面。 Silverlight參考池中包含System.Windows。 aspx參考池沒有。它所具有的是「WindowsBase」dll,它使System.Windows名稱空間(可能還有其他)在「使用」塊中可用。但是它默認不包含在項目中。

+0

這沒有爲我工作。我想使用System.Windows.Media.Imaging.BitmapImage,所以我想這不是在WindowsBase中。 (注意:我可以在sliverlight客戶端添加對System.Windows.DLL的引用,但不在服務器端。 – tkerwood 2011-09-07 04:17:45

+1

它位於 (#region Assembly System.Windows.dll,v2.0.50727 // c:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ Silverlight \ v4.0 \ System.Windows.dll #endregion) 所以只能在Silverlight客戶端上使用,我會看看使用System.Drawing。改爲圖片 – tkerwood 2011-09-07 04:40:16

+0

在Silverlight 5中,這似乎不起作用... – Knasterbax 2012-12-05 09:23:46

0

似乎Klay發佈的解決方案不適用於Silverlight 5(至少不在我的機器上)。

或者您可以使用 Vector2類從Microsoft.Xna.Framework

但這需要基於System.Windows.Vector代碼有點重寫,因爲VNA Vector2使用花車,而不是的雙打。