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

Adding mailmerge field at caret position from viewmodel.

2 Answers 21 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 20 Jul 2018, 02:09 PM

In code-behind it is easy to insert a merge field:

this.radRichTextBox.InsertField(new Telerik.Windows.Documents.Model.MergeField() { PropertyPath = "SomePath"  });

Is it possible, from the viewmodel, to the same thing?

2 Answers, 1 is accepted

Sort by
0
Accepted
Tanya
Telerik team
answered on 25 Jul 2018, 01:20 PM
Hello Peter,

To insert a merge field, you should have access to the document or the RadRichTextBox instance from the view model. If you can obtain the document, you can use the methods of RadDocumentEditor to insert the field. Would this be an option for you?

In case you would like to implement a pure MVVM approach, this would be more complex. You could create your own attached behaviors (similar to what is done with the RadRichTextBoxRibbonUI.RichTextCommand) and put the implementation there. An example could be found in the Attached Behavior/Properties help article, and some blog posts over the internet, for example, this one. In the original implementation of the logic in RadRichTextBox, we pass the corresponding command as value to the attached property, and in the code behind attach an event handler to the corresponding event.

Hope this helps.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Peter
Top achievements
Rank 1
answered on 17 Aug 2018, 04:48 AM

Hello Tanya,

Thank you so much for your post, I have look into the links you provided and it looks exactly as what I want.

Thanks again!

Best regards

Peter

Tags
RichTextBox
Asked by
Peter
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Peter
Top achievements
Rank 1
Share this question
or