StyleSheet 控制項沒有視覺表示,而且可以用來組織將套用至其他控制項的樣式。
StyleSheet 控制項可以包含任何數目的 <Style> 項目,或繼承自 Style 項目的項目。樣式表中的每一個Style 項目必須具有唯一的 Name 屬性 (Property)。您可以使用 Name 屬性 (Property) 從相同 MobilePage 物件上的其他控制項來參考 StyleSheet 控制項中的每一個Style 項目。
注意 StyleSheet 控制項會忽略其本身的樣式屬性 (Attribute)。在 StyleSheet 控制項本身設定樣式屬性 (Attribute) 對包含在 StyleSheet 控制項內樣式做為子系的樣式並沒有作用。
行動網頁也可以使用外部樣式表,而多個網頁還可以共用相同外部樣式表。若要建立外部樣式表,您必須在 .ascx 檔案中建立使用者控制項,並放置內含一組樣式的單一樣式表控制項。接下來,若要參考這個檔案,則在網頁上放置樣式表控制項並將它的 ReferencePath 屬性 (Property) 設為使用者控制項的相對 URL。如需使用者控制項的詳細資訊,請參閱建立自訂 ASP.NET Mobile 控制項文件。
行動控制項語法
需要的屬性和具程式碼功能的項目以粗體樣式標註。
<mobile:Stylesheetrunat="server"
id="id"
ReferencePath="externalReferencePath">
style declarations
</mobile:Stylesheet>
預設樣式表
ASP.NET 網頁架構定義預設樣式表做為支援一些樣式的樣式表。下列樣式可在預設樣式表中得到支援。
| 樣式 | 相關樣式值 |
|---|---|
| title | Font-Bold = true, FontSize = large |
| error | ForeColor = red |
| subcommand | FontSize = small |
您可以使用控制項或其他樣式來參考這些樣式。您也可以建立覆寫這些預設樣式的樣式。如需樣式特性和繼承的詳細資訊,請參閱樣式文件。
內含項目規則
下列控制項可以包含 StyleSheet 控制項。
| 控制項 | 註解 |
|---|---|
| System.Web.UI.MobileControls.MobilePage | MobilePage 控制項可以包含 0 或 1 個 StyleSheet 控制項。 |
StyleSheet 控制項可以包含下列控制項。
| 控制項 | 註解 |
|---|---|
| System.Web.UI.MobileControls.Style | StyleSheet 控制項可以包含任何數目的 StyleSheet 控制項或任何繼承自 Style 類別的其他類別。 |
裝置樣板
無
裝置的特定行為
StyleSheet 控制項沒有裝置的特定行為。
樣式表僅決定控制項所接受的特性值;並不決定裝置要使用那些特性做什麼。
範例
下列範例建立其中有Stylesheet 控制項在表單上的 .aspx 檔,並在名為 Mobile_style.ascx (內含樣式表和樣板資訊) 的外部檔案中建立使用者控制項。
StyleSheet 控制項是在 .aspx 檔中建立的。
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<mobile:StyleSheet
id="Style1"
ReferencePath="Mobile_style.ascx"
runat="server">
</mobile:StyleSheet>
<mobile:Form id=WelcomeForm runat="server" StyleReference="Style1"
title="Welcome" >
<mobile:Label runat="server" Text=" Welcome " StyleReference="title" />
</mobile:Form>
StyleSheet 的定義包含在外部的 Mobile_style.aspx 檔案中。
//Code in Mobile_style.ascx ( external stylesheet in a user control).
<Mobile:Stylesheet
runat="server">
<Style name="Style1">
<DeviceSpecific>
<Choice Filter="isHTML32">
<HeaderTemplate>
// Add other code or controls here, such as a banner
// or an AdRotator control.
</HeaderTemplate>
<FooterTemplate>
// Add other code or controls here, such as footers,
// or a copyright.
</FooterTemplate>
</Choice>
</DeviceSpecific>
</Style>
<Style name="Style2">
<DeviceSpecific>
<Choice Filter="isWML11">
<HeaderTemplate>
// Add other code or controls here.
// This section would point to WML .wbmp files.
</HeaderTemplate>
<FooterTemplate>
// Add other code or controls here.
// This section would point to WML .wbmp files.
</FooterTemplate>
</Choice>
</DeviceSpecific>
</Style>
</Mobile:Stylesheet>
請將下列裝置篩選條件定義加入至您的 web.config 檔。
<configuration>
<system.web>
<deviceFilters>
<filter name="isHTML32" compare="PreferredRenderingType" argument="html32" />
<filter name="isWML11" compare="PreferredRenderingType" argument="wml11" />
</deviceFilters>
</system.web>
</configuration>