IStyleSheet Interfaccia

Definizione

Definisce i metodi che una classe deve implementare per supportare la creazione di regole di stile.

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

Esempio

Nell'esempio di codice seguente viene usata l'implementazione di per illustrare a livello di codice la Header creazione di una nuova regola di IStyleSheet stile e la registrazione dell'oggetto personalizzato Style .

Nella prima parte dell'esempio viene creato un oggetto personalizzato Style e labelStylequindi registrato per il percorso corrente (URL). L'etichetta chiama quindi il label1MergeStyle metodo in modo che lo labelStyle stile venga applicato all'etichetta label1 .

La seconda parte dell'esempio definisce un altro oggetto personalizzato Style , bodyStylee imposta le relative proprietà per creare una nuova regola di stile.

Nota

Questa classe è destinata principalmente agli sviluppatori che vogliono creare un'implementazione personalizzata. In questo esempio viene illustrata l'implementazione fornita da .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>

Di seguito è riportato il file code-behind per la pagina Web nell'esempio precedente.

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.";
    }
}

Commenti

Le classi che implementano questa interfaccia possono usarla per supportare la creazione di regole di stile.

Per personalizzare il modo in cui vengono creati e registrati fogli di stile a catena, è necessario creare una classe che implementa questa interfaccia.

La HtmlHead classe implementa questa interfaccia per l'uso da parte di ASP.NET tramite la Header proprietà .

Nota

L'aggiunta o la modifica di stili o regole di stile a livello di codice durante i postback asincroni non è supportata. Quando si aggiungono funzionalità AJAX a una pagina Web ASP.NET, le aree di aggiornamento postback asincrone della pagina senza aggiornare l'intera pagina. Per altre informazioni, vedere panoramica Microsoft Ajax.

Metodi

CreateStyleRule(Style, IUrlResolutionService, String)

Quando implementato da una classe, crea una regola di stile per il tipo di elemento della lingua di documento o il selettore specificato.

RegisterStyle(Style, IUrlResolutionService)

Quando implementato da una classe, aggiunge una nuova regola di stile al foglio di stile incorporato nella sezione <head> di una pagina Web.

Si applica a

Vedi anche