MailMergeCurrentRecord does not return document when XamlDataProvider is used

2 posts, 0 answers
  1. Michael
    Michael avatar
    41 posts
    Member since:
    Oct 2010

    Posted 13 Aug 2013 Link to this post

    Hi,

    I have RadRichTextbox with XamlDataProvider and I use Mail Merge function.  In UI it works great.  But when I try to extract a current document on the backend (eg.  RadDocument resultDoc = myRadRichTextBox.Document.MailMergeCurrentRecord();) the resultDoc is empty.  If I do not use XamlDataProvider then it works fine. 

    Am I supposed to be extracting merged document differently when I use DataProvider?

    Some background ...  I am creating an email editor for mail merge.  Email text is saved in the database.  I binded XamlDataProvider's Xaml property to property on ViewModel.  This way I can save and load it to and from database.  User uses Mail Merge function to scroll through records,.  Then user can click on a Button which should send email with the current record being viewed.  So I need to extract the document. 

    Thank you in advance.
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 16 Aug 2013 Link to this post

    Hello Michael,

    Please find attached a sample project replicating the scenario you explained. I was unable to reproduce the issue you are observing, but it sounds like the ItemsSource of the MailMergeDataSource might not be set properly.

    In the attached solution ItemsSource is set in three different places:
    • In the constructor of the main window. This is needed when loading a document with the start of the application, for example using a format provider. In the particular project it is not needed because of the other two points below, I added it for future reference.
    • In the event handler of the SetupDocument event of XamlDataProvider. When in a data-bound scenario you change the string property to which the editor is bound this is what happens:A new document is created which raises the SetupDocument event of the data provider. At this point the document in the editor and the one which you can obtain from the event arguments are different. You can preprocess the document prior it has been shown, for example set its items source for future mail merge purposes, highlight part of the text, restore selection, etc.. Thereafter, the DocumentChanged event of the editor is raised.
    • In the event handler of the DocumentChanged event of RadRichTextBox. The event is raised when the document in the editor is changed. This means that not only is it raised when the string property in the view model is changed, but also if you open a new document using the UI (OpenDocumentCommand).

    Generally, setting the appropriate items source in the constructor (or on the Loaded event of the editor) and in the DocumentChanged event handler should suffice in preventing issues.

    I hope the provided information and sample solution will help in resolving the problem. In case you have any further comments or question do not hesitate to contact us back.

    Regards,
    Petya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top