diff --git a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs index c2bf019ee6..3176dee7a4 100644 --- a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs +++ b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs @@ -135,17 +135,17 @@ namespace Avalonia.Direct2D1 public IRenderTarget CreateRenderTarget(IEnumerable surfaces) { - var nativeWindow = surfaces?.OfType().FirstOrDefault(); - if (nativeWindow != null) + foreach (var s in surfaces) { - if(nativeWindow.HandleDescriptor != "HWND") - throw new NotSupportedException("Don't know how to create a Direct2D1 renderer from " + nativeWindow.HandleDescriptor); - return new HwndRenderTarget(nativeWindow); - } - var external = surfaces?.OfType(); - if (external != null) - { - + if (s is IPlatformHandle nativeWindow) + { + if (nativeWindow.HandleDescriptor != "HWND") + throw new NotSupportedException("Don't know how to create a Direct2D1 renderer from " + + nativeWindow.HandleDescriptor); + return new HwndRenderTarget(nativeWindow); + } + if (s is IExternalDirect2DRenderTargetSurface external) + return new ExternalRenderTarget(external, s_dwfactory); } throw new NotSupportedException("Don't know how to create a Direct2D1 renderer from any of provided surfaces"); }