IStyleSheet Interface

Definição

Define os métodos que uma classe deve implementar para suportar a criação de regras de estilo.

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

Exemplos

O exemplo de código seguinte utiliza a Header implementação de IStyleSheet para demonstrar a criação programática de uma nova regra de estilo e o registo do objeto personalizado Style .

Na primeira parte do exemplo, um objeto personalizado Style , labelStyle, é criado e depois registado para a localização atual (URL). Depois, a label1 etiqueta chama o MergeStyle método para que o labelStyle estilo seja aplicado à etiqueta.label1

A segunda parte do exemplo define outro objeto personalizado Style , bodyStylee define as suas propriedades para criar uma nova regra de estilo.

Note

Esta classe destina-se principalmente a programadores que pretendem criar uma implementação personalizada. Este exemplo demonstra a implementação fornecida pelo .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>

Segue-se o ficheiro code-behind da página Web no exemplo 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.";
    }
}

Observações

As classes que implementam esta interface podem usá-la para suportar a criação de regras de estilo.

Para personalizar a forma como as folhas de estilo em cascata são criadas e registadas, deve criar uma classe que implemente esta interface.

A classe HtmlHead implementa esta interface para uso por ASP.NET através da propriedade Header.

Note

Não é suportado adicionar ou modificar estilos ou regras de estilo programaticamente durante postbacks assíncronos. Quando adiciona capacidades AJAX a uma página Web ASP.NET, postbacks assíncronos atualizam regiões da página sem atualizar toda a página. Para mais informações, consulte Microsoft Ajax Overview.

Métodos

Name Description
CreateStyleRule(Style, IUrlResolutionService, String)

Quando implementado por uma classe, cria uma regra de estilo para o tipo de elemento de linguagem do documento especificado, ou seletor.

RegisterStyle(Style, IUrlResolutionService)

Quando implementado por uma classe, adiciona uma nova regra de estilo à folha de estilo embutida na <head> secção de uma página Web.

Aplica-se a

Ver também