Visual Studio 2010 RC关于WPF开发多个不同

开发 后端
本文将继续讨论Visual Studio 2010 RC关于WPF开发多个不同,希望通过本文能让大家对VS 2010有更深的了解。

本文是《辨析Visual Studio 2010 RC中WPF开发的改进》的续篇,将继续讲述Visual Studio 2010 RC在WPF方面的改进。

本不该在这个元宵佳节里写随笔。在这花好月圆时刻应该把酒当歌,莫使金樽空对月。特别是即汶川,海地之后的智利8.8级地震,更加让我嗅到了2012的味道。

但是千不该,万不该,还是让我找到了上一篇的答案,于是没有办法写下来与诸位分享。哥写的真不是寂寞,是答案——有图有真相的答案。

首先如果诸位不熟悉Helloj2ee的问题的,可以参见上一篇:Visual Studio 2010 RC关于WPF开发的X个不同之一——居然多了一个程序集引用

Helloj2ee总结出来的问题是 在VS2008里面 一个WPF程序至少需要四个程序集 system.dll,presentationframework.dll,windowsbase.dll和presentationcore.dll.

而Visual Studio 2010 RC里或者承蒙怕怕的韦恩卑鄙兄指点,说的准确些是WPF4。那么他需要的是五个程序集,除去刚才四个,还有就是System.xaml.dll。

现在Helloj2ee在这里告诉他的答案。如果在Visual Studio 2010 RC里编译,会报一个什么错误呢?

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'.

意思是已经定义了一个IQueryAmbient接口,而这个接口在System.xaml程序集当中。

如果您要去找IQueryAmbient接口,我打保票,您是寻访整个工程都找不到的。如果您在过去的MSDN,我是指3.5SP1的MSDN去搜索IQueryAmbient接口,那也是找不到的。

好在.Net4.0里可以找到的,这里是该接口的官方文档:http://msdn.microsoft.com/en-us/library/system.windows.markup.iqueryambient(VS.100).aspx

关键的修改之处在于FrameworkElement 实现了该接口。该接口是System.xaml.dll程序集当中的,而Window又派生自FrameworkElement,因此需要该程序集的引用。

这个接口非常简单只有一个称之为IsAmbientPropertyAvailable的方法,传递进去的参数是string,返回的是bool型。如下所示    

  1. // Summary:  
  2.     //     Queries for whether a specified property should be treated as ambient in  
  3.     //     the current scope.  
  4.     public interface IQueryAmbient  
  5.     {  
  6.         // Summary:  
  7.         //     Queries for whether a specified named property can be considered ambient  
  8.         //     in the current scope.  
  9.         //  
  10.         // Parameters:  
  11.         //   propertyName:  
  12.         //     The name of the property to check for ambience state.  
  13.         //  
  14.         // Returns:  
  15.         //     true if the requested property can be considered ambient; otherwise, false.  
  16.         bool IsAmbientPropertyAvailable(string propertyName);  
  17.     } 

这个接口的作用,我简单看了一下还是为了提高效率的。具体也可以请各位高手指点,我在这里抛砖先,你们尽管砸玉。

如果继续Reflector的话,不难发现原有的System.windows.markup命名空间当中的类和接口有相当一部分从过去的Windowsbase.dll移植到了System.xaml.dll当中。不妨看下面几张图。***张图是3.0版本下面的WindowsBase.dll中的System.windows.markup当中的类和接口,我只能说挺长,挺多。

接口

下一张就是4.0版本下面的windowsbase.dll当中的System.windows.markup当中的类和接口。

版本

可以看到相比上一张图,类和接口少了不少。不是凭空消失了相当一部分类和接口移到了System.xaml.dll程序集当中了。比如IComponetConnector接口等。下图就是System.xaml程序集当中的关于System.windows.markup当中的类和接口。

 类和接口

在这花好月圆夜,Helloj2ee写下了事实的真相。当然比较凌乱,概括一下就是三点:

(1)WPF4当中 FrameworkElement有所改动,它实现了IQueryAmbient接口,该接口正是传说中的System.xaml程序集中的接口,因此需要引用该程序集,绕不开,躲不过。

(2)实现该接口的目的,由Helloj2ee初步判定是为了提高效率;

(3)原来在3.5SP1之前,WindowsBase.dll承担了部分关于XAML的类和接口,在System.windows.markup明名空间当中,好了4.0来了,他把这当中的部分类和接口放在System.xaml这个程序集里。当然具体还请各位自己查证。

原文标题“VS2010RC关于WPF开发的X个不同之一——居然多了一个程序集引用”姊妹篇——有图有真相

链接:http://www.cnblogs.com/helloj2ee/archive/2010/02/28/1675288.html

【编辑推荐】

  1. 一线程序员的Visual Studio 2010 RC初体验
  2. Visual Studio 2010敏捷之道
  3. Visual Studio 2010开发绚丽Win 7应用程序
  4. 详解Visual Studio 2010敏捷测试驱动开发
  5. Visual Studio 2010升级Web开发功能

责任编辑:彭凡 来源: 博客园
相关推荐

2010-03-01 09:16:22

Visual Stud

2010-03-16 14:32:16

Visual Stud

2009-03-05 08:47:33

WPFUIVisual Stud

2012-05-11 15:51:11

VisualStudiWindows8

2010-03-04 10:28:48

Visual Stud

2010-02-22 14:00:29

Visual Stud

2011-02-13 17:10:28

Visual Stud

2009-12-02 09:43:38

Visual Stud

2009-11-11 13:24:51

Visual Stud

2009-11-04 09:16:00

Visual Stud

2009-11-10 13:43:37

Visual Stud

2009-12-15 09:36:32

Visual Stud

2010-07-20 08:43:00

Visual Stud

2010-03-05 13:48:50

Visual Stud

2010-02-24 14:16:56

Visual Stud

2010-06-01 13:32:15

Visual Stud

2013-09-03 17:59:00

Visual StudVisual Stud微软

2014-07-03 14:02:55

VS 2013Visual Stud

2012-06-07 10:31:39

Visual Stud

2009-12-01 10:49:44

Visual Stud
点赞
收藏

51CTO技术栈公众号