Class="WpfApplication7.App"xmlns="xmlns:
x="StartupUri="Page1.xaml">
此时你便拥有了一个基于Page导航的WPF应用程序。
#11.WPFvsSilverlightvsASP.NET
WPF,Silverlight,ASP.NET是微软开发的三大平台。
下面列出三种平台各自的特点
WPF:
1.开发Windows应用程序
2.以最丰富的用户控件和windows特定功能构建的客户端用户界面。
3.只能运行在Windows上
4.需要完整的.netframework支持。
Silverlight:
1.开发运行在Web端
2.轻量客户端,丰富的UI控件,类似于WPF客户端呈现
3.需要安装Silverlight插件在浏览器上
4.Silverlight的Moonlight版本可以在linux上运行
5.第一次加载时需要安装SL插件。
ASP.NET:
1.开发Web应用程序
2.轻量客户端,有着通用的Web控制
3.可以在服务端运行,也可以运行在所有支持HTML的客户端,包括移动设备的浏览器
4.不需要在客户端安装插件
#12.在3D硬件加速应用中使用Direct3D
虽然WPF提供3D绘制,但是3D应用中还是需要Direct3D来进行3D图形的绘制以呈现其最大性能。
而且WPF4.0是基于DirectX9.0,所以并不支持Direct3D10和Direct3D11。
#13.WPF的版本记录
虽然下面列出WPF版本的历史记录和相对应的VS版本。
由于WPF是.NETFramework框架一部分,所以版本号是跟着.NETFramework的。
下面就是其记录:
.NETFramework3.0–Nov,2006
∙1streleaseofWPF
∙CLRversion2.0
∙VisualStudio2005SP1
∙Inclw/WindowsVista
∙.NETFramework3.5–Nov,2007
∙VariousimprovementstoWPF
∙CLRversion2.0SP1
∙VisualStudio2008
∙Inclw/Windows7
∙.NETFramework3.5SP1–Aug,2008
∙Performanceimprovements(etal)toWPF
∙CLRversion2.0SP2
∙VisualStudio2008SP1
∙.NETFramework4.0–Apr,2010
∙VariousimprovementstoWPF
∙CLRversion4.0
∙VisualStudio2010
∙.NETFramework4.5–Aug,2012
∙VariousimprovementstoWPF
∙CLRversion4.5
∙VisualStudio2012
∙Inclw/Windows8
#14.SilverlightandWPF不同之处
Silverlight原名叫做WPF/E(WPF/Everywhere),个人觉得原名很拽。
通过名字就可以知道SL和WPF遵循相同的编程模型和大部分空间,可以理解为SL是WPF的一个浏览器特殊版本。
核心区别:
1.WPF只运行在WIndows平台
2.WPF需要.NETFramework
3.SL是WPF控件的一个子集
4.SL使用了.NETFRAMEWORK和CLR的子集
WPF独有:
1.支持流文件Flowdocument
2.支持动态资源Dynamicresources
3.Mergeddictionaries(SL3已有)
4.重置样式到一个新的FrameworkElement
5.Style继承(SL4已有)
6.隐式样式TargetType属性(SL5已有)
7.Styles,ControlTemplates,DataTemplate的Triggers
8.Routedcommands
9.自定义标记扩展(Custommarkupextensions)(SL5已有)
10.运行时访问的可视化和逻辑树(VisualTree已有SLSPY工具也可以看到)
11.一些WPF独享的控件(AccessText,BulletChrome,ButtonChrome,ContextMenu,Decorator,DocumentPageView,DocumentViewer,GridViewColumnHeader,GridViewRowPresenter,GroupBox,GroupItem,InkCanvas,Menu,MenuItem,PageContent,Ribbon,Separator,StatusBar,TickBar,ToolBar,Track,UniformGrid)
SL独有:
1.深度缩放(DeepZoom)
2.一些SL独享控件(AutoCompleteBox,DataPager,DescriptionViewer,HyperlinkButton,MultiScaleImage,NumericUpDown,ValidationSummary)
#15system.windows命名空间
大多数wpf用户界面相关的类的命名空间都是system.windows或者其子命名空间。
下面列出一些在system.window命名空间下的类:
1Application–EncapsulatedaWPFapplication
2Clipboard–Transferdatato/fromclipboard
3ContentElement–Baseclassforcontentselements,forflow-stylepresentation
4DataObject–Transferingdata
5DataTemplate–Visualstructureofadataobject
6DependencyObject–Objectthatparticipatesindependencypropertysystem
7DependencyProperty–Propertiesthatsupportdatabinding,inheritance,etc.
8EventManager–Event-relatedutilitymethods
9FrameworkElement–ExtendsUIElement&providessupportforlogicaltree,etal
10MessageBox-Displaysamessagebox
11ResourceDictionary–DictionarythatcontainsWPFresources
12RoutedEvent–Routedevent
13Style–Sharingofproperties/resourcesbetweeninstances
14UIElement–Baseclassforgraphicalelements
15UIElement3D–Baseclassfor3Delements
16Window–Windowinuserinterface
#16独立和浏览器承载的应用程序
wpf可以创建独立的windows应用程序在windows环境下运行或者创建浏览器承载的应用程序,在浏览器中运行。
浏览器承载的应用程序也被称之为xbaps(xaml浏览器应用程序)。
发布的XBAP托管在一个web的服务器上,访问者机器首先下载和安装应用程序所需要的silverlight插件,当用户第一次浏览xbap页面时,用户界面会显示在浏览器的窗口中。
XBAPS可以在ie和firefox中完美运行。
#17WPF单位
在windowsforms开发中,控件的大小是根据像素生成的。
而在wpf中使用的是wpf单位。
1wpfunit=1/96inch。
这个说明了在96dpi下,一个wpf单位为一个像素(pixel)。
这就意味着在120dpi下,一个wpf单位是1.25pixel。
由于WPF所有的元素都是使用wpf单位来进行大小绘制的,所有的控件都是会基于设备系统的DPI。
这样就可以保证在不同的设备上有着相同的物理尺寸。
换句话说就是一个96WPF单位的元素无论是在96dpi下还是120dpi下都是1英寸大小(96pixel=1英寸)。
在WindowsForm下如果想做到设备无关性,需要设置AutoScaleMode,但在WPF中是自动的。
计算公式:
#pixels=(#WPFUnits)*(DPI/96)
#18WPF结构
下面结构图展示了WPF主要的一些dll之间的依赖关系:
下面列出在上图中的dll:
System.Windows.Presentation.dll–Containssometypesrelatedtoadd-ins
PresentationFramework.Aero.dll–ImplementsAerothemeforWPFcontrols
∙PresentationFramework.Classic.dll–ImplementsClassicthemeforWPFcontrols
∙PresentationFramework.dll–ContainsmostofthemainWPFcontrols,aswellassupportfordatabinding
∙PresentationUI.dll–Containssomeresourcesrelatedtothemes&somesupportclassesforSystem.Windows.Documents
∙ReachFramework.dll–ContainstypesrelatedtoprintingandXPSdocuments
∙System.Printing.dll–Containsmaintypesrelatedtoprinting
∙PresentationCore.dll-LowerleveltypesforvisualrenderinglikeUIElement.AlsoDragDropsupport.
∙System.Windows.Input.Manipulations.dll-Implementationofinputmanipulators
∙UIAutomationProvider.dll-SupportforUIAutomation(foraccessibility)
∙WindowsBase.dll-Lower-leveltypeslikeDependencyObjectandDependencyProperty
∙UIAutomationTypes.dll–Basictypes