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>