You are not logged in.
This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.
Anyone, able to get a print preview working in wpf using the winform calls, as there are not any calls coded for the WPF version....
using System.Windows.Xps;
using System.Windows.Xps.Packaging;
using unvell.ReoGrid.Print;
namespace unvell.ReoGrid.Print
{
partial class PrintSession
{
internal void Init() { }
public void Dispose() { }
/// <summary>
/// Start output document to printer.
/// </summary>
public void Print()
{
throw new NotImplementedException("WPF Print is not implemented yet. Try use Windows Form version to print document as XPS file.");
}
}
}
namespace unvell.ReoGrid
{
partial class Worksheet
{
}
}
#endif // WPF
#endif // PRINT
Using the below code in the codebehind of a wpf window gives a simple screenshot of the gridcontrol , but isn't really useful for true printing...
private string _previewWindowXaml =
@"<Window
xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation'
xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml'
Title ='Print Preview - @@TITLE'
Height ='500' Width ='700'
WindowStartupLocation ='CenterOwner'>
<DocumentViewer Name='dv1'/>
</Window>";
internal void DoPreview(string title)
{
string fileName =
"C:\\Users\\sirmf\\Documents\\Visual Studio 2015\\Projects\\ReoGridBetterTextTest\\printPreview.xps";
// FlowDocumentScrollViewer visual = (FlowDocumentScrollViewer)(this.FindName("grid"));
try
{
// write the XPS document
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.ReadWrite))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(grid);
}
// Read the XPS document into a dynamically generated
// preview Window
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.Read))
{
FixedDocumentSequence fds = doc.GetFixedDocumentSequence();
string s = _previewWindowXaml;
s = s.Replace("@@TITLE", title.Replace("'", "'"));
using (var reader = new System.Xml.XmlTextReader(new StringReader(s)))
{
Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window;
DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer;
dv1.Document = fds as IDocumentPaginatorSource;
preview.ShowDialog();
}
}
}
finally
{
if (File.Exists(fileName))
{
try
{
File.Delete(fileName);
}
catch
{
}
}
}
} // end of DoPreview()
Offline
Nice workaround!
Offline