tags:

views:

37

answers:

3

Is it possible to create a bitmap of a window that hasn't been shown without using screenshots?

What I want to do is start my application, and have a main window that displays other windows. I use visual brush to display them after they've been shown, and the image stays after the window is closed, but how do I show an image of the window prior to Window.Show()?

+1  A: 

I would guess that the window isn't rendered until it is needed, so there would be no way to get the flattened bitmap of it. I wonder if you could somehow make it "show" without being shown? Can you use Window.Hide() to your advantage? Just throwing it out there.

Also makes me think--why would you want to get a bitmap of a Window? Windows are for presenting UI, not for displaying as an abstract representation of a UI choice. Maybe creating an abstract icon for each choice would be more usable?

Patrick Szalapski
The window's Bitmap becomes the link to the window. The reason I want to do it this way is because if I make changes to the form, I don't want to have to change the image each time, so if the window creates a bitmap of itself, then I don't have to keep changing it every time I update the window's controls. Window.Hide() doesn't help either. If I hide it too fast, nothing shows up.
Sivvy
OK, but I was just pointing out from a usability standpoint that the icon (or preview) probably shouldn't change all the time since it is an abstraction of the actual window they will get. However, I could see some cases where it makes sense--some web browsers and even Windows 7 does this already with the live previews. Once you figure out how, it would be nice to create a PreviewableWindow class that inherits from or decorates Window.
Patrick Szalapski
A: 

You should get everything you need here: http://www.west-wind.com/weblog/posts/150676.aspx and here: http://www.codeproject.com/KB/WPF/WPF-Image-to-WebPage.aspx

The key is the RenderTargetBitmap class

Rob Fonseca-Ensor
I'm familiar with the RenderTargetBitmap class. What I need to do is render the bitmap from something that technically doesn't exist.
Sivvy
Actually, you need to render a bitmap from something that's not *visible*. you're going to have to instantiate the window in order to render it - just don't call show().
Rob Fonseca-Ensor
+1  A: 

No way to do this without creating the Window first, as it won't be in the visual tree until it is created. You may create it in an area outside your working area and generate the bitmap from there. You need it laid-out first also because of bindings, layout transforms, etc.

Gustavo Cavalcanti