Language: C#
Handling snapshot of scrollable content using Silverlight's WriteableBitmap
1: public static void ExportToJpeg() { 2: prepare(true); 3: SaveFileDialog saveDialog = new SaveFileDialog 4: { 5: Filter = "JPEG Files (*.jpeg)|*.jpeg", 6: DefaultExt = ".jpeg", 7: }; 8: if ((bool)saveDialog.ShowDialog()) { 9: using (Stream fileStream = saveDialog.OpenFile()) { 10: WriteableBitmap bitmap = new WriteableBitmap(containerPanel, null); 11: if (bitmap != null) saveToJpegFile(bitmap, fileStream); 12: } 13: } 14: prepare(false); 15: } 16: 17: private static void prepare(bool imageExport) { 18: scrollViewer.VerticalScrollBarVisibility = imageExport ? 19: ScrollBarVisibility.Hidden : ScrollBarVisibility.Visible; 20: bool hasScroll = scrollViewer.ViewportHeight < scrollViewer.ExtentHeight; 21: if (!hasScroll) return; 22: double scrollViewerHeight; 23: string pluginHeight; 24: if (imageExport) { 25: previousHeight = scrollViewer.ViewportHeight; 26: double heightDifference = scrollViewer.ExtentHeight - previousHeight; 27: double pluginActualHeight = App.Current.Host.Content.ActualHeight; 28: scrollViewerHeight = scrollViewer.ExtentHeight; 29: pluginHeight = String.Format("{0}px", pluginActualHeight + heightDifference); 30: } else { 31: scrollViewerHeight = previousHeight; 32: pluginHeight = "100%"; 33: } 34: scrollViewer.Height = scrollViewerHeight; 35: HtmlPage.Plugin.SetStyleAttribute("height", pluginHeight); 36: containerPanel.UpdateLayout(); 37: }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

