ASP.NET 2.0 行動控制項 (System.Web.UI.MobileControls) 透過 StyleSheet 控制項 集中管理樣式,支援:
<mobile:Form>) 之下,不可放入 Panel/容器內。<mobile:Form id="Form1" runat="server">
<mobile:StyleSheet id="StyleSheet1" runat="server" />
<!-- 其他控制項 -->
</mobile:Form>
TitleStyle, ErrorStyle, ItemStyle)。ForeColor, BackColor, Font-Bold, Font-Size, Alignment, Wrap, CssClass 等。<mobile:Label id="lblTitle" runat="server" StyleReference="TitleStyle" Text="歡迎光臨" />
<mobile:Label id="lblError" runat="server" StyleReference="ErrorStyle" ForeColor="Red" />
<mobile:List id="lstItems" runat="server" ItemStyle-StyleReference="ItemStyle" />
StyleReference 參考 StyleSheet 中的命名樣式。ForeColor="Blue"),優先權高於 StyleReference。<mobile:Panel id="pnlContent" runat="server" StyleReference="ContainerStyle">
<mobile:Label id="lbl1" runat="server" Text="項目一" />
<mobile:Label id="lbl2" runat="server" Text="項目二" />
</mobile:Panel>
Panel 套用 ContainerStyle,內部 Label 自動繼承字體、顏色、對齊等屬性,除非個別覆寫。
在樣式編輯器中定義裝置篩選器,依裝置特性套用不同樣式值:
| 篩選器名稱 | 比較運算式 | 套用樣式調整 |
|---|---|---|
| IsSmallScreen | ScreenPixelsWidth < 200 | Font-Size="Small", Wrap="True" |
| IsColorDevice | IsColor = true | ForeColor="Blue", BackColor="White" |
| SupportsCss | SupportsCss = true | CssClass="ModernStyle" |
執行時 ASP.NET 依 Request.Browser 能力比對篩選器,動態選擇樣式定義。
<%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<mobile:Form id="Form1" runat="server">
<mobile:StyleSheet id="StyleSheet1" runat="server">
<mobile:Style Name="TitleStyle" ForeColor="White" BackColor="Navy" Font-Bold="True" Font-Size="Large" Alignment="Center" />
<mobile:Style Name="ItemStyle" ForeColor="Black" Font-Size="Medium" />
<mobile:Style Name="ErrorStyle" ForeColor="Red" Font-Bold="True" />
<!-- 裝置篩選器範例 -->
<mobile:DeviceSpecific Name="TitleStyle">
<mobile:Choice Filter="IsSmallScreen" Font-Size="Small" />
</mobile:DeviceSpecific>
</mobile:StyleSheet>
<mobile:Label StyleReference="TitleStyle" Text="行動商城" />
<mobile:List id="lstProducts" runat="server" ItemStyle-StyleReference="ItemStyle">
<mobile:ListItem Text="筆記型電腦" />
<mobile:ListItem Text="智慧型手機" />
</mobile:List>
<mobile:Label id="lblError" StyleReference="ErrorStyle" Text="庫存不足" Visible="False" />
</mobile:Form>
developer.openwave.com。ASP.NET 行動控制項已淘汰。現代方案:
ASP.NET 2.0 StyleSheet 控制項提供行動網頁集中式樣式管理、裝置篩選器適配、容器繼承三大核心能力。雖然行動控制項已成歷史,但其樣式抽離、裝置適配、容器層級繼承的設計哲學,深刻影響現代響應式 CSS 框架與設計系統的架構思維。