FrameworkElement.DefaultStyleKey 속성

정의

테마 스타일을 사용하거나 정의할 때 이 컨트롤에 대한 스타일을 참조하는 데 사용할 키를 가져오거나 설정합니다.

protected public:
 property System::Object ^ DefaultStyleKey { System::Object ^ get(); void set(System::Object ^ value); };
protected internal object DefaultStyleKey { get; set; }
member this.DefaultStyleKey : obj with get, set
Protected Friend Property DefaultStyleKey As Object

속성 값

스타일 키입니다. 테마 스타일 조회의 일부로 올바르게 작동하려면 이 값은 스타일이 지정되는 컨트롤의 Type이어야 합니다.

예제

다음 예제에서는 주의에서 설명한 종속성 속성 메타데이터 재정의 사용량을 보여 줍니다. 이 코드는 전용 컨트롤 라이브러리 어셈블리에서 사용할 사용자 지정 컨트롤 클래스 NumericUpDown 를 정의합니다. 설명된 정적 생성자는 일부 프라이빗 초기화 함수를 참조하고, 클래스 처리기를 등록하고(또 다른 일반적인 컨트롤 서브클래싱 시나리오, 라우트된 이벤트를 처리됨으로 표시 및 클래스 처리 참조) 마지막으로 클래스의 종속성 속성 메타데이터를 재정의 DefaultStyleKeyNumericUpDown 합니다. DefaultStyleKey 항상 고유한 형식을 의도한 키로 반환합니다. 즉, 테마 스타일 시스템에서 스타일이 아닌 임의의 컨트롤에 대한 스타일을 조회하는 데 사용하는 규칙입니다.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;
using System.Windows.Automation;
using System.Globalization;
using System.Diagnostics;

namespace CustomControlLibrary
{
    public partial class NumericUpDown : Control
    {
        static NumericUpDown()
        {
            InitializeCommands();

            // Listen to MouseLeftButtonDown event to determine if slide should move focus to itself
            EventManager.RegisterClassHandler(typeof(NumericUpDown), 
                Mouse.MouseDownEvent, new MouseButtonEventHandler(NumericUpDown.OnMouseLeftButtonDown), true);

            DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown), new FrameworkPropertyMetadata(typeof(NumericUpDown)));
        }
    }
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input

Namespace CustomControlLibrary
    Public Partial Class NumericUpDown
        Inherits Control

        Shared Sub New()
            InitializeCommands()

            ' Listen to MouseLeftButtonDown event to determine if slide should move focus to itself
            EventManager.RegisterClassHandler(GetType(NumericUpDown), Mouse.MouseDownEvent, New MouseButtonEventHandler(AddressOf NumericUpDown.OnMouseLeftButtonDown), True)

            DefaultStyleKeyProperty.OverrideMetadata(GetType(NumericUpDown), New FrameworkPropertyMetadata(GetType(NumericUpDown)))
        End Sub
    End Class
End Namespace

이 예제의 전체 소스 코드는 Visual Basic에서 사용할 수 있습니다.

설명

이 속성은 일반적으로 직접 속성 접근자를 통해 설정되지 않습니다. 대신 새 파생 클래스를 만들 때마다 이 종속성 속성의 형식별 메타데이터를 FrameworkElement 재정의합니다. 컨트롤을 파생하는 경우 컨트롤 파생 클래스(또는 동등한 클래스 초기화)의 정적 생성자 내에서 식별자에 대해 DefaultStyleKeyProperty 메서드를 호출 OverrideMetadata 합니다.

컨트롤은 일반적으로 이 속성의 기본값을 자체 형식으로 재정의하지만, 경우에 따라 테마 사전의 스타일이 있는 기본 형식을 사용할 수도 있습니다. 이는 기본 컨트롤의 컨트롤 템플릿이 파생된 컨트롤의 시각적 표현을 완전히 정의하고 파생 형식이 노출하는 추가 멤버가 컨트롤 템플릿의 일부로 추가 요소가 필요하지 않은 경우에만 실용적입니다.

요소 또는 컨트롤이 의도적으로 테마 스타일을 사용하지 않도록 하려면 속성을 true로 설정합니다OverridesDefaultStyle.

종속성 속성 정보

식별자 필드 DefaultStyleKeyProperty
메타 데이터 속성 설정 true AffectsMeasure

적용 대상

추가 정보