StyleSheet 控件可以包含任意数目的 <Style> 元素或从 Style 元素继承的元素。样式表中的每个 Style 元素必须具有唯一的 Name 属性。您可以使用 Name 属性从相同 MobilePage 对象上的其他控件引用 StyleSheet 控件中的每个 Style 元素。
注意 StyleSheet 控件忽略它自己的样式属性。在 StyleSheet 控件自身上设置样式属性对作为子级包含在 StyleSheet 控件中的样式不起任何作用。
移动页也可以使用外部样式表,并且多个页可以共享同一个外部样式表。若要创建外部样式表,请在 .ascx 文件中创建一个用户控件,然后将具有一组样式的单个样式表控件放置在其中。然后,为了引用此文件,请将一个样式表控件放置在该页上并将其 ReferencePath 属性设置为该用户控件的相对 URL。有关用户控件的更多信息,请参见创建自定义 ASP.NET 移动控件文档。
移动控件语法
必需的属性、默认值和具有代码特征的元素以粗体显示。
<mobile:Stylesheet
runat="server"
id="id"
ReferencePath="externalReferencePath">
style declarations
</mobile:Stylesheet>
默认样式表
ASP.NET 页框架将默认样式表定义为支持多个样式的样式表。默认样式表中支持以下样式。
Style 关联的样式值
title Font-Bold = true、FontSize = large
error ForeColor = red
subcommand FontSize = small
您可以通过控件或其他样式引用这些样式。还可以创建重写这些默认样式的样式。有关样式特性和继承的更多信息,请参见样式文档。
包容规则
以下控件可以包含 StyleSheet 控件。
控件 说明
System.Web.UI.MobileControls.MobilePage MobilePage 控件可以不包含 StyleSheet 控件,也可以包含一个 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>







