다음을 통해 공유


UIElement.Focusable 속성

정의

요소가 포커스를 받을 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다. 종속성 속성입니다.

public:
 property bool Focusable { bool get(); void set(bool value); };
public bool Focusable { get; set; }
member this.Focusable : bool with get, set
Public Property Focusable As Boolean

속성 값

요소를 포커스할 수 있는지 true. 그렇지 않으면 false. 기본값은 false.

구현

예제

다음 예제 코드는 특정 사용자 지정 컨트롤에 대한 컨트롤 템플릿을 보여 줍니다. 이 컨트롤은 템플릿 내의 요소 중 하나에 Focusablefalse 설정합니다.

<Window.Resources>
  <Style x:Key="TextBoxNoScrollViewer" TargetType="{x:Type TextBoxBase}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type TextBoxBase}">
          <Border 
            CornerRadius="2" 
            Background="{TemplateBinding Background}" 
            BorderThickness="{TemplateBinding BorderThickness}" 
            BorderBrush="{TemplateBinding BorderBrush}"  
          >
            <!-- 
            The control template for a TextBox or RichTextBox must
            include an element tagged as the content host.  An element is 
            tagged as the content host element when it has the special name
            PART_ContentHost.  The content host element must be a ScrollViewer,
            or an element that derives from Decorator.  
            -->
            <AdornerDecorator 
              x:Name="PART_ContentHost"
              Focusable="False" 
            />
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</Window.Resources>

설명

포커스가 있는 요소만 키보드 입력을 받습니다.

Focusable 실제로 종속성 속성에 대한 Microsoft .NET 속성 접근자입니다. 이 특정 종속성 속성에는 파생된 요소 클래스, 특히 컨트롤에서 다르게 설정된 명백한 "기본" 값이 자주 있습니다. 이는 일반적으로 다음 두 가지 방법 중 하나로 발생합니다.

  • 종속성 속성은 특정 파생 클래스에서 상속되지만 파생 클래스는 종속성 속성의 메타데이터를 재정의하고 속성 기본값을 변경합니다.

  • 스타일 또는 템플릿은 종속성 속성 값을 다르게 설정하는 요소에 적용됩니다.

예를 들어 ButtonUIElement직접 CLR(공용 언어 런타임) 속성으로 Focusable 상속하더라도 Button 컨트롤에 대한 Focusable 명백한 "기본값"은 true. 이는 Focusable 종속성 속성의 적용된 메타데이터 값이 클래스 계층 구조에서 ButtonUIElement 사이에 위치한 Control 기본 클래스의 정적 생성자 내에서 재정의되었기 때문입니다.

Control 또는 파생 클래스에서 상속되는 경우 Control 이 속성의 기본값을 true다시 정의합니다.

Control 파생 클래스인 Label 상속된 경우 기본값은 다시 false다시 정의됩니다.

종속성 속성 정보

식별자 필드 FocusableProperty
true 설정된 메타데이터 속성 없음

상속자 참고

Control아니라 직접 UIElement 파생할 때는 기본적으로 요소에 포커스를 맞출 수 없으므로 요소의 포커스를 지정할 수 있는지 여부를 고려합니다. 요소의 포커스를 지정하려면 다음과 같이 형식의 정적 생성자 내에서 이 속성에 대한 메타데이터를 재정의합니다.

FocusableProperty.OverrideMetadata(typeof(myElement), new UIPropertyMetadata(true));
FocusableProperty.OverrideMetadata(GetType(myElement), New UIPropertyMetadata(True))

여기서 myElement 메타데이터 값을 재정의하는 형식의 클래스 이름이어야 합니다.

적용 대상

추가 정보