Mo Valipour
Mo Valipour

Reputation: 13496

Render a "User Control" to an Image File

I followed the approach explained here to generate customized live tile appearance for my application.

The only problem this approach has is that you need to build the entire set of controls programmatically via c# code.

I tried adding a User Control to my application (LiveTile.xaml) and used the same approach by this time instead of adding all Rectangles and TextBlocks I instantiated the UserControl and rendered it on bitmap.

var tileUserControl = new MyLiveTile(); // this internally has a simple 50x50 red grid
bitmap.Render(tileUserControl, new TranslateTransform());

BUT: I no longer see anything rendered to the bitmap image. The image is entirely left black (even with very very simple xaml inside the user control).

Does anybody know how can this be achieved?

What I also tried

none seem to have an effect on the output.

Thanks.

Upvotes: 0

Views: 963

Answers (2)

Daniel Santos
Daniel Santos

Reputation: 15928

Im Having this issue too. If You are using Backgroud agent to update your live tile, im not sure about the control will load or be able to mesuse/arrange its content or render they.

I'll try to wait until Load event get fired and try to render the controls again.

Upvotes: 0

Claus Jørgensen
Claus Jørgensen

Reputation: 26336

Mind posting your entire rendering routine? You'll minimum have to call bitmap.Invalidate().

Also, you might need to wait for the Control.Loaded event, to ensure that all the FrameworkElements on your UserControl have actually been loaded and rendered.

Rendering the UserControl to early, will just render the UserControl element itself, without any of it's children (ie. a black square)

Upvotes: 2

Related Questions