UIElement.Focusable 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
요소가 포커스를 받을 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다. 이 속성은 종속성 속성입니다.
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 속성 접근자입니다. 이 특정 종속성 속성에는 파생된 요소 클래스, 특히 컨트롤에서 다르게 설정된 명백한 "기본" 값이 자주 있습니다. 이는 일반적으로 다음 두 가지 방법 중 하나로 발생합니다.
- 종속성 속성은 특정 파생 클래스에서 상속되지만 파생 클래스는 종속성 속성의 메타데이터를 재정의하고 속성 기본값을 변경합니다.
- 스타일 또는 템플릿은 종속성 속성 값을 다르게 설정하는 요소에 적용됩니다.
예를 들어 컨트롤의 FocusableButton 명백한 "기본값"은 trueCLR(공용 언어 런타임) 속성으로 직접 Button상속 Focusable 되더라도 UIElement 됩니다. 종속성 속성에 적용 Focusable 된 메타데이터 값이 클래스 계층 구조 간에 ControlButton 위치하는 기본 클래스의 정적 생성자 내에서 재정의 UIElement 되었기 때문입니다.
상속된 Control 클래스 또는 파생 클래스 Control 인 경우 이 속성 true의 기본값을 다시 정의합니다.
상속되는 Label 경우(파생 클래스인 Control ) 기본값이 다시 정의됩니다 false.
종속성 속성 정보
| 항목 | 가치 |
|---|---|
| 식별자 필드 | FocusableProperty |
메타데이터 속성이 다음으로 설정됩니다. true |
None |
상속자 참고
직접 파생될 UIElement 때(원본 Control이 아니라) 기본적으로 요소에 포커스를 맞출 수 없으므로 요소의 포커스를 지정할 수 있는지 여부를 고려합니다. 요소의 포커스를 지정하려면 다음과 같이 형식의 정적 생성자 내에서 이 속성에 대한 메타데이터를 재정의합니다.
FocusableProperty.OverrideMetadata(typeof(myElement), new UIPropertyMetadata(true));
FocusableProperty.OverrideMetadata(GetType(myElement), New UIPropertyMetadata(True))
myElement 는 메타데이터 값을 재정의하는 형식의 클래스 이름이어야 합니다.