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之前,必須先設定:
XAML与HTML一样是flow layout,Grid類似HTML中的Table,使整個頁面的顯示方式變成網格式区域。微軟還推荐使用StackPanel,DockPanel等继承自Panel的規劃方式,Panel在使用上的類似HTML的{{<}}DIV{{>}}{{<}}\DIV{{>}}。
WPF提供了一個最重要的頁面導航物件NavigationService,可用來調整頁面之用。NavigationService物件提供有下列功能:
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>