PrintPreview cw = new PrintPreview();
cw.ShowPreview(rtb);
cw.HasCloseButton = false;
//Hook up a handler to the Closed event before we display the PrintPreview window by calling the Show() method.
cw.Closed += (t, a) =>
{
if (cw.DialogResult.Value)
{
PrintDocument theDoc = new PrintDocument();
theDoc.PrintPage += (s, args) =>
{
args.PageVisual = rtb;
args.HasMorePages = false;
};
theDoc.EndPrint += (s, args) =>
{
MessageBox.Show("The document printed successfully", "Text Editor", MessageBoxButton.OK);
};
theDoc.Print("Silverlight 4 Text Editor");
ReturnFocus();
}
};
cw.Show();