-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
WindowExtensions.cs
39 lines (34 loc) · 982 Bytes
/
WindowExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.IO;
using System.Threading.Tasks;
using Microsoft.Maui.Media;
#if __IOS__ || MACCATALYST
using PlatformView = UIKit.UIWindow;
#elif MONOANDROID
using PlatformView = Android.App.Activity;
#elif WINDOWS
using PlatformView = Microsoft.UI.Xaml.Window;
#elif TIZEN
using PlatformView = Tizen.NUI.Window;
#endif
namespace Microsoft.Maui
{
public static partial class WindowExtensions
{
public static Task<IScreenshotResult?> CaptureAsync(this IWindow window)
{
#if PLATFORM
if (window?.Handler?.PlatformView is not PlatformView platformView)
return Task.FromResult<IScreenshotResult?>(null);
if (!Screenshot.Default.IsCaptureSupported)
return Task.FromResult<IScreenshotResult?>(null);
return CaptureAsync(platformView);
#else
return Task.FromResult<IScreenshotResult?>(null);
#endif
}
#if PLATFORM
async static Task<IScreenshotResult?> CaptureAsync(PlatformView window) =>
await Screenshot.Default.CaptureAsync(window);
#endif
}
}