共用方式為


Style.RegisterStyle(String, Type, Object, Boolean) 方法

定義

註冊樣式屬性並傳回唯一索引鍵,以便查閱。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 mobile Apps & Sites with ASP.NET

public:
 static System::Object ^ RegisterStyle(System::String ^ name, Type ^ type, System::Object ^ defaultValue, bool inherit);
public static object RegisterStyle (string name, Type type, object defaultValue, bool inherit);
static member RegisterStyle : string * Type * obj * bool -> obj
Public Shared Function RegisterStyle (name As String, type As Type, defaultValue As Object, inherit As Boolean) As Object

參數

name
String

樣式屬性的名稱。

type
Type

用於屬性的型別。

defaultValue
Object

屬性的預設值。

inherit
Boolean

指出樣式是否繼承自父物件。 預設為 true

傳回

用於查閱的唯一索引鍵。

範例

下列範例示範如何使用 RegisterStyle 方法來註冊支持繼承的字串屬性,以及其預設值為空字串 (“”) 。 這個不完整的範例包含公用屬性,其實作會使用基類的預設索引器屬性來存取此屬性的專案。

public class CustomStyle : 
    System.Web.UI.MobileControls.Style
    {
        private string themeNameKey;

        public CustomStyle(string name)
        {
            themeNameKey = 
                RegisterStyle(name, typeof(String), 
                    String.Empty, true).ToString();
        }
        
        public string ThemeName
        {
            get
            {
                return this[themeNameKey].ToString();
            }
            set
            {
                this[themeNameKey] = value;
            }
        }
    }
Public Class CustomStyle
    Inherits System.Web.UI.MobileControls.Style
    Private themeNameKey As String

    Public Sub New(ByVal name As String)
        themeNameKey = _
            RegisterStyle(name, GetType(String), _
                String.Empty, True).ToString()
    End Sub
    
    Public Property ThemeName() As String
        Get
            Return Me(themeNameKey).ToString()
        End Get
        Set(ByVal value As String)
            Me(themeNameKey) = value
        End Set
    End Property
End Class

備註

只從繼承的樣式類別呼叫。

適用於

另請參閱