IStyleSheet Interface
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Define os métodos que uma classe deve implementar para dar suporte à 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 a seguir usa a Header implementação para IStyleSheet demonstrar programaticamente a criação de uma nova regra de estilo e o registro do objeto personalizado Style .
Na primeira parte do exemplo, um objeto labelStyle
personalizado Style é criado e registrado para a URL (localização atual). Em seguida, o label1
rótulo chama o MergeStyle método para que o labelStyle
estilo seja aplicado ao label1
rótulo.
A segunda parte do exemplo define outro objeto bodyStyle
personalizado Style e define suas propriedades para criar uma nova regra de estilo.
Observação
Essa classe destina-se principalmente a desenvolvedores que desejam 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>
Veja a seguir o arquivo code-behind da página da 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.";
}
}
Comentários
Classes que implementam essa interface podem usá-la para dar suporte à criação de regras de estilo.
Para personalizar a forma como as folhas de estilo em cascata são criadas e registradas, você deve criar uma classe que implemente essa interface.
A HtmlHead classe implementa essa interface para uso ASP.NET por meio da Header propriedade.
Observação
Não há suporte para adicionar ou modificar estilos ou regras de estilo programaticamente durante postbacks assíncronos. Quando você adiciona recursos do AJAX a uma página da Web ASP.NET, postbacks assíncronos atualizam regiões da página sem atualizar a página inteira. Para obter mais informações, consulte a Visão geral do Microsoft Ajax.
Métodos
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 inserida na seção |