WPF筆記(二)
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left><A name=Applications><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>.NET Framework</SPAN></A>、</SPAN>System.Windows</SPAN>、標記和代碼隱藏構成了</SPAN> WPF </SPAN>應用程序開發體驗的基礎。此外,</SPAN>WPF </SPAN>還為創造具有豐富內容的用戶體驗提供了全面的功能。為了打包此內容并將其作為</SPAN>“</SPAN>應用程序</SPAN>”</SPAN>發送給用戶,</SPAN>WPF </SPAN>提供了一些類型和服務,它們統稱為</SPAN>“</SPAN>應用程序模型</SPAN>”</SPAN>。該應用程序模型既支持開發獨立應用程序,也支持開發瀏覽器承載的應用程序。</SPAN>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 2.7pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-outline-level: 3" class=MsoNormal align=left>獨立應用程序</B></SPAN>
<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>對于獨立應用程序,您可以使用</SPAN> Window </SPAN>類創建可從菜單欄和工具欄上訪問的窗口和對話框。下圖演示了帶有一個主窗口和一個對話框的獨立應用程序。</SPAN>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 0pt; mso-pagination: widow-orphan" class=MsoNormal align=left>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>對于瀏覽器承載的應用程序(稱為<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XAML </SPAN>瀏覽器應用程序<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> (XBAP)</SPAN>),您可以創建能夠使用超鏈接(<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Hyperlink </SPAN>類)導航的頁面<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> (Page) </SPAN>和頁函數<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> (PageFunction</SPAN><SPAN style="DISPLAY: none; FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt; mso-hide: all" lang=EN-US><(Of <</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt" lang=EN-US>(</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>T</SPAN><SPAN style="DISPLAY: none; FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt; mso-hide: all" lang=EN-US>>)></SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt; mso-bidi-font-size: 12.0pt" lang=EN-US>)</SPAN><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>)</SPAN>。下圖演示了<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> Internet Explorer 7 </SPAN>承載的<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XBAP </SPAN>中的頁面。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US><v:shape style="WIDTH: 435.75pt; HEIGHT: 344.25pt" id=_x0000_i1026 alt="所承載的應用程序的兩頁" type="#_x0000_t75"><v:imagedata o:href="ms-help://MS.MSDNQTR.v90.chs/wpf_conceptual/art/WPFIntroFigure27.png" src="file:///C:\DOCUME~1\user\LOCALS~1\Temp\msohtml1\04\clip_image003.png">/v:imagedata/v:shapeo:p/o:p</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p /o:p</SPAN></P>
<P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 2.7pt; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-outline-level: 3" class=MsoNormal align=left>應用程序類
<P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left><SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>XBAP </SPAN>和獨立應用程序通常非常復雜,需要額外的應用程序范圍的服務,包括啟動和生存期管理、共享屬性以及共享資源。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>Application </SPAN>類封裝了這些服務以及更多內容,并且只需使用<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XAML </SPAN>即可實現,如下面的示例所示。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US><Application</SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US> xmlns="
<P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>StartupUri="MainWindow.xaml" /></SPAN></P> <P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P> <P style="TEXT-ALIGN: left; MARGIN: 0cm 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>此標記是獨立應用程序的應用程序定義,并指示<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> WPF </SPAN>創建一個在應用程序啟動時自動打開<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> MainWindow </SPAN>的<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> Application </SPAN>對象。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P> <P style="TEXT-ALIGN: left; MARGIN: 6.8pt 0cm 3.4pt; mso-pagination: widow-orphan" class=MsoNormal align=left>理解<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> Application </SPAN>的一個關鍵概念在于,它為獨立應用程序和瀏覽器承載的應用程序提供了一個通用的支持平臺。例如,瀏覽器承載的應用程序可以使用前面的<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XAML</SPAN>,以便在<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US> XBAP </SPAN>啟動時自動導航到某個頁面,如下面的示例所示。<SPAN style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 8.5pt; mso-bidi-font-family: 宋體; mso-font-kerning: 0pt" lang=EN-US>o:p/o:p</SPAN></P> <P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US>o:p /o:p</SPAN></P> <P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US><Application</SPAN></P> <P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US> xmlns="
<P style="TEXT-INDENT: 21.75pt; MARGIN: 0cm 0cm 0pt" class=MsoNormal><SPAN lang=EN-US> StartupUri="HomePage.xaml" /></SPAN></P>