private void Print(object sender, RoutedEventArgs e) { PrintSettings printSettings = PrintSettings.Default; UIElement container = this.Content as UIElement; ScrollViewer containerPanel = Helper.FindVisualChildren<ScrollViewer>(container).FirstOrDefault(); var origParentDirection = containerPanel.FlowDirection; var origDirection = (containerPanel.Content as FrameworkElement).FlowDirection; if (containerPanel != null && containerPanel.FlowDirection == FlowDirection.RightToLeft) { containerPanel.FlowDirection = FlowDirection.LeftToRight; (containerPanel.Content as FrameworkElement).FlowDirection = FlowDirection.RightToLeft; } var window = new Window(); string tempFileName = System.IO.Path.GetTempFileName(); System.IO.File.Delete(tempFileName); using (XpsDocument xpsDocument = new XpsDocument(tempFileName, FileAccess.ReadWrite, System.IO.Packaging.CompressionOption.Fast)) { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument); (containerPanel.Content as FrameworkElement).Margin = new Thickness(20); writer.Write((containerPanel.Content as FrameworkElement), printSettings.PrintTicket); var doc = xpsDocument.GetFixedDocumentSequence(); doc.PrintTicket = printSettings.PrintTicket; window.FlowDirection = System.Windows.FlowDirection.RightToLeft; window.Content = new DocumentViewer { Document = doc }; window.Margin = new Thickness(10); window.ShowDialog(); } (containerPanel.Content as FrameworkElement).FlowDirection = origDirection; containerPanel.FlowDirection = origParentDirection; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)