Visual Studio 2010 RC關(guān)于WPF開發(fā)多個不同
本文是《辨析Visual Studio 2010 RC中WPF開發(fā)的改進(jìn)》的續(xù)篇,將繼續(xù)講述Visual Studio 2010 RC在WPF方面的改進(jìn)。
本不該在這個元宵佳節(jié)里寫隨筆。在這花好月圓時(shí)刻應(yīng)該把酒當(dāng)歌,莫使金樽空對月。特別是即汶川,海地之后的智利8.8級地震,更加讓我嗅到了2012的味道。
但是千不該,萬不該,還是讓我找到了上一篇的答案,于是沒有辦法寫下來與諸位分享。哥寫的真不是寂寞,是答案——有圖有真相的答案。
首先如果諸位不熟悉Helloj2ee的問題的,可以參見上一篇:Visual Studio 2010 RC關(guān)于WPF開發(fā)的X個不同之一——居然多了一個程序集引用
Helloj2ee總結(jié)出來的問題是 在VS2008里面 一個WPF程序至少需要四個程序集 system.dll,presentationframework.dll,windowsbase.dll和presentationcore.dll.
而Visual Studio 2010 RC里或者承蒙怕怕的韋恩卑鄙兄指點(diǎn),說的準(zhǔn)確些是WPF4。那么他需要的是五個程序集,除去剛才四個,還有就是System.xaml.dll。
現(xiàn)在Helloj2ee在這里告訴他的答案。如果在Visual Studio 2010 RC里編譯,會報(bào)一個什么錯誤呢?
error CS0012: The type 'System.Windows.Markup.IQueryAmbient' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
意思是已經(jīng)定義了一個IQueryAmbient接口,而這個接口在System.xaml程序集當(dāng)中。
如果您要去找IQueryAmbient接口,我打保票,您是尋訪整個工程都找不到的。如果您在過去的MSDN,我是指3.5SP1的MSDN去搜索IQueryAmbient接口,那也是找不到的。
好在.Net4.0里可以找到的,這里是該接口的官方文檔:http://msdn.microsoft.com/en-us/library/system.windows.markup.iqueryambient(VS.100).aspx
關(guān)鍵的修改之處在于FrameworkElement 實(shí)現(xiàn)了該接口。該接口是System.xaml.dll程序集當(dāng)中的,而Window又派生自FrameworkElement,因此需要該程序集的引用。
這個接口非常簡單只有一個稱之為IsAmbientPropertyAvailable的方法,傳遞進(jìn)去的參數(shù)是string,返回的是bool型。如下所示
- // Summary:
- // Queries for whether a specified property should be treated as ambient in
- // the current scope.
- public interface IQueryAmbient
- {
- // Summary:
- // Queries for whether a specified named property can be considered ambient
- // in the current scope.
- //
- // Parameters:
- // propertyName:
- // The name of the property to check for ambience state.
- //
- // Returns:
- // true if the requested property can be considered ambient; otherwise, false.
- bool IsAmbientPropertyAvailable(string propertyName);
- }
這個接口的作用,我簡單看了一下還是為了提高效率的。具體也可以請各位高手指點(diǎn),我在這里拋磚先,你們盡管砸玉。
如果繼續(xù)Reflector的話,不難發(fā)現(xiàn)原有的System.windows.markup命名空間當(dāng)中的類和接口有相當(dāng)一部分從過去的Windowsbase.dll移植到了System.xaml.dll當(dāng)中。不妨看下面幾張圖。***張圖是3.0版本下面的WindowsBase.dll中的System.windows.markup當(dāng)中的類和接口,我只能說挺長,挺多。
下一張就是4.0版本下面的windowsbase.dll當(dāng)中的System.windows.markup當(dāng)中的類和接口。
可以看到相比上一張圖,類和接口少了不少。不是憑空消失了相當(dāng)一部分類和接口移到了System.xaml.dll程序集當(dāng)中了。比如IComponetConnector接口等。下圖就是System.xaml程序集當(dāng)中的關(guān)于System.windows.markup當(dāng)中的類和接口。
在這花好月圓夜,Helloj2ee寫下了事實(shí)的真相。當(dāng)然比較凌亂,概括一下就是三點(diǎn):
(1)WPF4當(dāng)中 FrameworkElement有所改動,它實(shí)現(xiàn)了IQueryAmbient接口,該接口正是傳說中的System.xaml程序集中的接口,因此需要引用該程序集,繞不開,躲不過。
(2)實(shí)現(xiàn)該接口的目的,由Helloj2ee初步判定是為了提高效率;
(3)原來在3.5SP1之前,WindowsBase.dll承擔(dān)了部分關(guān)于XAML的類和接口,在System.windows.markup明名空間當(dāng)中,好了4.0來了,他把這當(dāng)中的部分類和接口放在System.xaml這個程序集里。當(dāng)然具體還請各位自己查證。
原文標(biāo)題:“VS2010RC關(guān)于WPF開發(fā)的X個不同之一——居然多了一個程序集引用”姊妹篇——有圖有真相 鏈接:http://www.cnblogs.com/helloj2ee/archive/2010/02/28/1675288.html 【編輯推薦】