IStyleSheet Interfaz

Definición

Define los métodos que debe implementar una clase para admitir la creación de reglas de estilo.

public interface class IStyleSheet
public interface IStyleSheet
type IStyleSheet = interface
Public Interface IStyleSheet

Ejemplos

En el ejemplo de código siguiente se usa la Header implementación de para mostrar mediante programación la creación de IStyleSheet una nueva regla de estilo y el registro del objeto personalizado Style .

En la primera parte del ejemplo, se crea un objeto personalizado Style , labelStyle, y después se registra para la ubicación actual (URL). A continuación, la label1 etiqueta llama al MergeStyle método para que el labelStyle estilo se aplique a la label1 etiqueta.

La segunda parte del ejemplo define otro objeto personalizado Style , bodyStyley establece sus propiedades para crear una nueva regla de estilo.

Nota

Esta clase está pensada principalmente para desarrolladores que desean crear una implementación personalizada. En este ejemplo se muestra la implementación proporcionada por el .NET Framework.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="istylesheetcs.aspx.cs" Inherits="istylesheetcs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>    
<body>
    <form id="form1" runat="server">
        <h1>IStyleSheet Example</h1>
        <asp:Label 
          id="label1" 
          runat="server">
        </asp:Label>
        <br /><br />
        <asp:Label 
          id="label2" 
          runat="server">
        </asp:Label>
    </form>
  </body>
</html>
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="istylesheetvb.aspx.vb" Inherits="istylesheetvb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>IStyleSheet Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <h1>IStyleSheet Example</h1>
        <asp:Label 
          id="label1" 
          runat="server">
        </asp:Label>
        <br /><br />
        <asp:Label 
          id="label2" 
          runat="server">
        </asp:Label>
    </form>
  </body>
</html>

A continuación se muestra el archivo de código subyacente de la página web en el ejemplo anterior.

public partial class istylesheetcs : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Create a Style object to hold style rules to apply to a Label control.
        Style labelStyle = new Style();

        labelStyle.ForeColor = System.Drawing.Color.DarkRed;
        labelStyle.BorderColor = System.Drawing.Color.DarkBlue;
        labelStyle.BorderWidth = 2;

        // Register the Style object so that it can be merged with 
        // the Style object of the controls that use it.
        Page.Header.StyleSheet.RegisterStyle(labelStyle, null);

        // Merge the labelCssStyle style with the label1 control's
        // style settings.
        label1.MergeStyle(labelStyle);
        label1.Text = "This is what the labelCssStyle looks like.";

        // Create a Style object for the <BODY> section of the Web page.
        Style bodyStyle = new Style();

        bodyStyle.ForeColor = System.Drawing.Color.Blue;
        bodyStyle.BackColor = System.Drawing.Color.LightGray;

        // Add the style to the header of the current page.
        Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "BODY");

        // Add text to the label2 control to see the label without 
        // the labelStyle applied to it.  
        label2.Text = "This is what the bodyStyle looks like.";
    }
}

Comentarios

Las clases que implementan esta interfaz pueden usarlas para admitir la creación de reglas de estilo.

Para personalizar la forma en que se crean y registran las hojas de estilos en cascada, debe crear una clase que implemente esta interfaz.

La HtmlHead clase implementa esta interfaz para usarla ASP.NET a través de la Header propiedad .

Nota

No se admite la adición o modificación de estilos o reglas de estilo durante postbacks asincrónicos. Cuando se agregan funcionalidades de AJAX a una página web de ASP.NET, las postbacks asincrónicas actualizan las regiones de la página sin actualizar toda la página. Para obtener más información, consulte Introducción a Microsoft Ajax.

Métodos

CreateStyleRule(Style, IUrlResolutionService, String)

Cuando lo implementa una clase, crea una regla de estilo para el tipo de elemento del lenguaje de documento especificado, o selector.

RegisterStyle(Style, IUrlResolutionService)

Cuando lo implementa una clase, agrega una nueva regla de estilo a la hoja de estilos incrustada en la sección <head> de una página Web.

Se aplica a

Consulte también