디바이스 표시 정보

Browse sample. 샘플 찾아보기

이 문서에서는 .NET 다중 플랫폼 앱 UI(.NET MAUI) IDeviceDisplay 인터페이스를 사용하여 디바이스의 화면 메트릭에 대한 정보를 읽는 방법을 설명합니다. 이 인터페이스를 사용하여 앱이 실행되는 동안 화면이 깨어 있는 상태를 유지하도록 요청할 수 있습니다.

인터페이스의 IDeviceDisplay 기본 구현은 속성을 통해 DeviceDisplay.Current 사용할 수 있습니다. IDeviceDisplay 인터페이스와 DeviceDisplay 클래스는 모두 네임스페이스에 Microsoft.Maui.Devices 포함됩니다.

기본 표시 정보

이 속성은 MainDisplayInfo 화면 및 방향에 대한 정보를 반환합니다. 다음 코드 예제에서는 페이지의 이벤트를 사용하여 Loaded 현재 화면에 대한 정보를 읽습니다.

private void ReadDeviceDisplay()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    sb.AppendLine($"Pixel width: {DeviceDisplay.Current.MainDisplayInfo.Width} / Pixel Height: {DeviceDisplay.Current.MainDisplayInfo.Height}");
    sb.AppendLine($"Density: {DeviceDisplay.Current.MainDisplayInfo.Density}");
    sb.AppendLine($"Orientation: {DeviceDisplay.Current.MainDisplayInfo.Orientation}");
    sb.AppendLine($"Rotation: {DeviceDisplay.Current.MainDisplayInfo.Rotation}");
    sb.AppendLine($"Refresh Rate: {DeviceDisplay.Current.MainDisplayInfo.RefreshRate}");

    DisplayDetailsLabel.Text = sb.ToString();
}

또한 인터페이스는 IDeviceDisplay 디바이스 방향 DisplayOrientation.LandscapeDisplayOrientation.Portrait이 변경될 때와 같이 화면 메트릭이 변경될 때 발생하는 이벤트를 제공합니다MainDisplayInfoChanged.

화면 유지

속성을 로 설정하여 디바이스가 잠기거나 화면이 KeepScreenOn 꺼지도록 방지할 수도 있습니다 true. 다음 코드 예제에서는 스위치 컨트롤을 누를 때마다 화면 잠금을 전환합니다.

private void AlwaysOnSwitch_Toggled(object sender, ToggledEventArgs e) =>
    DeviceDisplay.Current.KeepScreenOn = AlwaysOnSwitch.IsToggled;

플랫폼 간 차이점

이 섹션에서는 디바이스 디스플레이의 플랫폼별 차이점에 대해 설명합니다.

플랫폼의 차이점이 없습니다.