A new feature of Windows 8.1 is that developers can render the XAML tree to a bitmap. This can be useful in exposing a screenshot of a part of an application with the image Share contract. Note that Windows 8.1 supports sharing a screenshot of any app through a new Share charm option. This is slightly more specific and also lets you control properties like Title.
In order to make this happen, you have to go through a few hoops. Here is a sample event handler that wires up the pieces together including converting to a PNG image to bring the file size down. See MSDN’s “How to share an image” article for configuration.
In this case, we have a ScrollViewer in an ListView control (it’s used in a continuous document viewing section of an app). The method shares what is currently visible on the screen.
Here is an example from my Army Field Manuals app. Note that the share item doesn’t include the app border, which is handy in this case:
Additional references used:
- “Windows 8.1 RenderTargetBitmap” by Geoff Webber-Cross
- “How to get byte from IBuffer” answered by Min Zhu
- XAML render to bitmap sample (Windows 8.1) on MSDN
Note: This blog post is based on Windows 8.1 RTM and Visual Studio 2013 RC.