3
Grid TestGrid = new Grid();
TestGrid.Background = new SolidColorBrush(Colors.AliceBlue);
TestGrid.Height = 500;
TestGrid.Width = 500;
await bitmapRender.RenderAsync(TestGrid, 500, 500);

This code in its last statement gives me the following error:

System.ArgumentException

Value does not fall within the expected range.

What's wrong in this apparently simple code?

Edit: Futher details on the bug:

{System.ArgumentException: Value does not fall within the expected range. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Picture_Slide.MainPage.d__0.MoveNext()}

Aditya
  • 310
  • 1
  • 3
  • 11

2 Answers2

2

perhaps it's the same as in WINRT, it can't render something which is not in the visual tree, or in popup, etc... Look here for details: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx From 'XAML visuals and RenderTargetBitmap capture capabilities' title

notacat
  • 671
  • 6
  • 11
  • 2
    In which case how do I achieve what WritableBitmap can in a Silverlight app? I need to generate it from code without having it in the visual tree. – Aditya May 11 '14 at 18:14
  • @Aditya On WinRT you can render only those elements that are in VisualTree - [similar question](http://stackoverflow.com/q/22896979/2681948). – Romasz May 11 '14 at 18:26
  • you should add it to the visual tree and hide somehow if you don't need it on the screen. Maybe place under some border – notacat May 11 '14 at 22:40
0

In case you want to use RenderAsync in a backgroundAgent use XamlRenderingBackgroundTask

http://social.msdn.microsoft.com/Forums/en-US/43295c90-43e8-4b08-8a25-958a1c3d0a0b/explanation-on-windowsuixamlmediaxamlrenderingbackgroundtask?forum=WindowsPhonePreviewSDK

Ouadie
  • 13,005
  • 4
  • 52
  • 62