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.
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 >>