FocusManager 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
애플리케이션의 모든 요소에서 포커스 작업 및 이벤트를 전역으로 관리할 수 있는 도우미 클래스입니다.
UWP에 해당하는 WinUI 2 API: Microsoft.UI.Xaml.Input.FocusManager(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조).
public ref class FocusManager sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class FocusManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class FocusManager
Public NotInheritable Class FocusManager
- 상속
- 특성
Windows 요구 사항
| 디바이스 패밀리 |
Windows 10 (10.0.10240.0에서 도입되었습니다.)
|
| API contract |
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)
|
예제
TryMoveFocus를 사용하여 화살표 키를 사용하여 UI 요소 사이를 트래버스합니다.
private void Page_KeyUp(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Up)
{
// Mimic Shift+Tab when user hits up arrow key.
FocusManager.TryMoveFocus(FocusNavigationDirection.Previous);
}
else if (e.Key == Windows.System.VirtualKey.Down)
{
// Mimic Tab when user hits down arrow key.
FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
}
}
설명
가능하면 FocusManager 이벤트 대신 포커스 라우트된 이벤트를 사용하는 UIElement 것이 좋습니다.
FocusManager는 애플리케이션의 특정 요소가 에서 버블링된 이벤트를 수신하지 않는 고급 시나리오를 UIElement위한 것입니다. 예를 들어 , 또는 MenuFlyout 앱 UI의 일부로 표시되지만 실제로는 시각적 트리 계층 구조의 일부가 아닌 자체 포커스 범위인 시각적 "오버레이" 개체PopupTooltip가 있습니다. 이 Popup경우 프로그래밍 방식으로 true로 설정하고 IsOpen 팝업의 내/외부로 포커스가 이동할 때 발생합니다.
다음은 예제를 설명하는 몇 가지 기본 태그입니다.
<Page …>
<Grid …>
<Popup …>
<StackPanel Name="StackPanel3" …>
<TextBlock Text="StackPanel3" />
<Button Content="Button5" …/>
</StackPanel>
</Popup>
<TextBlock Text="Grid" … />
<StackPanel Name="StackPanel1" …>
<TextBlock Text="StackPanel1" …/>
<Button Content="Button1" …/>
<Button Content="Button2" … />
</StackPanel>
<StackPanel Name="StackPanel2" …>
<TextBlock Text="StackPanel2" …/>
<Button Content="Button3" … />
<Button Content="Button4" … />
</StackPanel>
</Grid>
</Page>
이 경우 팝업에는 StackPanel3이 포함되며, 그러면 Button5가 포함됩니다. true로 설정되고 포커스가 Button1에서 Button5로 이동하면 IsOpen LosingFocus 및 LostFocus 이벤트가 시각적 트리에 버블 업됩니다(StackPanel1, Grid 및 Page는 이러한 이벤트를 모두 가져옵니다). 그러나 StackPanel3만 Button5에서 버블 업되는 후속 GettingFocus 및 GotFocus 이벤트를 받습니다(Grid 및 Page는 Popup과 부모-자식 관계에 있지 않으므로 그렇지 않음).
애플리케이션에는 논리 포커스가 있는 여러 요소가 있을 수 있습니다(포커스 범위 수에 따라 다름). 그러나 애플리케이션의 한 요소만 키보드 포커스를 가질 수 있습니다.
논리 포커스가 있는 요소가 여러 개 있을 수 있지만 포커스 범위당 논리적 포커스가 있는 요소는 하나뿐입니다. 논리적 포커스가 있는 요소에는 반드시 키보드 포커스가 있는 것은 아니지만 키보드 포커스가 있는 요소에는 논리적 포커스가 있습니다.
버전 기록
| Windows 버전 | SDK 버전 | 추가된 값 |
|---|---|---|
| 1703 | 15063 | FindFirstFocusableElement |
| 1703 | 15063 | FindLastFocusableElement |
| 1703 | 15063 | FindNextElement(FocusNavigationDirection) |
| 1703 | 15063 | FindNextElement(FocusNavigationDirection,FindNextElementOptions) |
| 1703 | 15063 | TryMoveFocus(FocusNavigationDirection,FindNextElementOptions) |
| 1803 | 17134 | TryFocusAsync |
| 1803 | 17134 | TryMoveFocusAsync(FocusNavigationDirection) |
| 1803 | 17134 | TryMoveFocusAsync(FocusNavigationDirection,FindNextElementOptions) |
| 1809 | 17763 | GettingFocus |
| 1809 | 17763 | GotFocus |
| 1809 | 17763 | LosingFocus |
| 1809 | 17763 | LostFocus |
| 1903 | 18362 | GetFocusedElement(XamlRoot) |
메서드
이벤트
| GettingFocus |
요소가 실제로 포커스를 받기 전에 발생합니다. 이 이벤트는 이벤트가 버블링되는 동안 포커스가 이동되지 않도록 동기적으로 발생합니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Xaml.Input.FocusManager.GettingFocus(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| GotFocus |
컨테이너 요소 내의 요소(포커스 범위)가 포커스를 받을 때 발생합니다. 이 이벤트는 비동기적으로 발생하므로 버블링이 완료되기 전에 포커스가 이동할 수 있습니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Xaml.Input.FocusManager.GotFocus(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| LosingFocus |
포커스가 있는 현재 요소에서 대상 요소로 포커스가 이동하기 전에 발생합니다. 이 이벤트는 이벤트가 버블링되는 동안 포커스가 이동되지 않도록 동기적으로 발생합니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Xaml.Input.FocusManager.LosingFocus(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
| LostFocus |
컨테이너 요소 내의 요소(포커스 범위)가 포커스를 잃을 때 발생합니다. 이 이벤트는 비동기적으로 발생하므로 버블링이 완료되기 전에 포커스가 다시 이동할 수 있습니다. UWP에 해당하는 WinUI 2 API: Microsoft.UI.Xaml.Input.FocusManager.LostFocus(Windows 앱 SDK WinUI의 경우 Windows 앱 SDK 네임스페이스 참조). |
적용 대상
추가 정보
피드백
다음에 대한 사용자 의견 제출 및 보기