XAML Browser Application
XAML Browser Application,最开始叫xapp,后来在Sept CTP中叫wba,是美国微软公司所提出的新技术,以XAML作为用户接口(UI)之描述,寄宿(hosted)在浏览器(IE web browser sandbox)中运行的程序。XBAP可以取代ActiveX、Java Applet、Flash等功能,有人称之为下一代的ActiveX(next-generation ActiveX)。XAML Browser Application的扩展名是.xbap。
环境设置
在运行XBAP之前,必须先设置:
- .NET Framework 3.0 Runtime
- Windows SDK for .NET Framework 3.0
- Visual Studio 2005 extensions for .NET Framework 3.0(November 2006 CTP)
特点
- XBAPS更易于与DHTML结合。
- XBAPS一旦使用宽松XAML(loose XAML)或使用IFRAME,必运行于安全的沙盒(secure sandbox)。
- XBAPS可以使用WPF(Windows Presentation Foundation)的98.2%的功能。
- XBAPS必须运行于iFrame之下。
- XBAPS必须运行于DocumentObject应用程序之下,利用querystring沟通。
- XBAPS目前仅支持IE6或IE7。
安全性
- XBAP程序无法使用文件系统(file system)。
- XBAP程序无法调用对话窗口(dialog)。
- XBAP程序如同DHTML,是网络直接安装运行,可能遇到安全性问题,所以XBAP进程必须具备内嵌数字签名。<ManifestKeyFile>指定签字用的证书文档名,<ManifestCertificateThumbprint>指定证明文档摘要。
- XBAP中只允许通过HTTP和SOAP访问Web Services。
规划
XAML与HTML一样是flow layout,Grid类似HTML中的Table,使整个页面的显示方式变成网格式区域。微软还推荐使用StackPanel,DockPanel等继承自Panel的规划方式,Panel在使用上的类似HTML的{{<}}DIV{{>}}{{<}}\DIV{{>}}。
导航
NavigationService
WPF提供了一个最重要的页面导航对象NavigationService,可用来调整页面之用。NavigationService对象提供有下列功能:
- public void Navigate(Uri source)
- public void Refresh()
- public void StopLoading()
- public void GoBack()
- public void GoForward()
- public void AddBackEntry()
- public void RemoveBackEntry()
- public static NavigationService GetNavigationService(DependencyObject dependencyObject);
structured navigation
structured navigation可用于处理页面与页面之间的数据共享。WPF支持PageFunction这样的页面标签。
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=" (页面存档备份,存于)"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="StructuredNavigationSample.TestPageFunction"
x:TypeArguments="sys:String"
Title="Test for Page Function" WindowWidth="250" WindowHeight="150">
......
</PageFuntion>
范例
将3D动画置入iframe:
<iframe height="130"
width="130"
src="3d_animation.xaml" />
将XBAP置入iframe:
<html>
<head>
<body>
<iframe name="Iframe1" src="%fullpathtoyourgadgetdirectory%\TestBrowserApp.xbap" ></iframe>
</body>
</html>
差异
WinFX Windows Application和WinFX Web Browser Application有些微的差别,在.xaml文件中,Browser Application中,缺省起始页的根元素(root element)为Page;Windows Application中,缺省起始页的根元素为Window。另外,Window class无法在Browser Application中使用,因为IE浏览器中的WPF进程是在部分信任的沙箱(sandbox)内运行。
<Page x:Class="XAMLBrowserApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=" (页面存档备份,存于)"
WindowTitle="Hello world" WindowWidth="560" WindowHeight="400"
Title="Page1"
>
<Grid>
</Grid>
</Page>