CodePaste Logo
New Snippet New Recent Snippets Recent Snippets My Snippets My Snippets My Favorites Favorites Web Code Search Snippets Search
Sign inor Register
Language: csharp

Handling snapshot of scrollable content using Silverlight's WriteableBitmap

1867 Views   
public static void ExportToJpeg() { prepare(true); SaveFileDialog saveDialog = new SaveFileDialog { Filter = "JPEG Files (*.jpeg)|*.jpeg", DefaultExt = ".jpeg", }; if ((bool)saveDialog.ShowDialog()) { using (Stream fileStream = saveDialog.OpenFile()) { WriteableBitmap bitmap = new WriteableBitmap(containerPanel, null); if (bitmap != null) saveToJpegFile(bitmap, fileStream); } } prepare(false); } private static void prepare(bool imageExport) { scrollViewer.VerticalScrollBarVisibility = imageExport ? ScrollBarVisibility.Hidden : ScrollBarVisibility.Visible; bool hasScroll = scrollViewer.ViewportHeight < scrollViewer.ExtentHeight; if (!hasScroll) return; double scrollViewerHeight; string pluginHeight; if (imageExport) { previousHeight = scrollViewer.ViewportHeight; double heightDifference = scrollViewer.ExtentHeight - previousHeight; double pluginActualHeight = App.Current.Host.Content.ActualHeight; scrollViewerHeight = scrollViewer.ExtentHeight; pluginHeight = String.Format("{0}px", pluginActualHeight + heightDifference); } else { scrollViewerHeight = previousHeight; pluginHeight = "100%"; } scrollViewer.Height = scrollViewerHeight; HtmlPage.Plugin.SetStyleAttribute("height", pluginHeight); containerPanel.UpdateLayout(); }
by Danijel Stulic
  August 17, 2009 @ 5:18am
Tags:
Add a comment


Report Abuse
brought to you by:
West Wind Techologies