This is a migrated thread and some comments may be shown as answers.

Native Print Error

2 Answers 63 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jaco De Villiers
Top achievements
Rank 2
Jaco De Villiers asked on 29 Mar 2012, 06:29 AM
Hi,

I am getting an error when I try to print a RichTextBox in native mode.  The Error is "Dialogs must be user initiated.  If I Use Mode=Html then it works but the document prints incorrectly.  When I export to PDF it works and prints correctly.  See code in viewmodel below, I have also tried the dispatcher associated with the RichTextBox.  The RichTextBox is close to the root of the visual tree, but has a height of 0px.  It Throws the exception on line "rtb.Print( package.Name, Telerik.Windows.Documents.UI.PrintMode.Native ); ".  I have also tried to execute the "CreateDocument". Without dispatching on the UI thread explicitly

Please Help
Jaco

/// <summary>
/// Prints the specified package.
/// </summary>
/// <param name="package">The package.</param>
public void Print(PMPackage package, RadRichTextBox rtb)
{
    GalaSoft.MvvmLight.Threading.DispatcherHelper.UIDispatcher.BeginInvoke((Action)(() =>
    {
        rtb.Document = CreateDocument(package);
    }));
    rtb.Print(package.Name, Telerik.Windows.Documents.UI.PrintMode.Native);
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Rajmund
Top achievements
Rank 1
answered on 30 Mar 2012, 09:39 AM
I have the same problem, it was:  dialog must be user initiated exception (not used dispatcher - too long time for creating document), or  nullreferenceexception (with dispatcher).
I solved this problem by added line before create document:
rtb.Document.Measure(RadDocument.MAX_DOCUMENT_SIZE);

In telerik examples this line is only in Export method and that method working correctly :)
0
Jaco De Villiers
Top achievements
Rank 2
answered on 31 Mar 2012, 12:30 AM
Worked like a charm!
Tags
RichTextBox
Asked by
Jaco De Villiers
Top achievements
Rank 2
Answers by
Rajmund
Top achievements
Rank 1
Jaco De Villiers
Top achievements
Rank 2
Share this question
or