The following code throws a System.ArgumentException critical exception from the RenderAsync "Value is not in the expected range" method. If, on the other hand, my canvas is part of the visible XAML tree, it works. Is it impossible to display any XAML that does not appear on the screen?
Canvas c = new Canvas(); c.Width = 40; c.Height = 40; c.Background = new SolidColorBrush(Color.FromArgb(0xff, 0x80, 0xff, 0x80)); RenderTargetBitmap x = new RenderTargetBitmap(); await x.RenderAsync(c);
I almost thought this answer would work, but no luck, I suppose this only applies to WPF: Create a WPF element behind the scenes and display a bitmap
UPDATE:
So far, my best idea is to put the canvas that I want to display on the current visible page, but put it under what is usually the root UIElement that fills the screen so that it is not visible to the user:
<Grid> <Canvas x:Name="HiddenCanvas"/> <Grid x:Name="mainElement" Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> </Grid> </Grid>
It is not beautiful, but it seems to work. Let's see if anyone can do better
source share