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

RichTextBox - MailMerge how to add INCLUDEPICTURE field from UI

2 Answers 192 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Saykor
Top achievements
Rank 2
Saykor asked on 02 Sep 2014, 05:52 PM
Hi all,
1. Please go to: http://demos.telerik.com/silverlight/#RichTextBox/MailMerge
2. In the UI you will see Insert Merge Field
3. Click it and select RecipientPhoto

This add {MERGEFIELD RecipientPhoto}
How to add {INCLUDEPICTURE {MERGEFIELD RecipientPhoto}} ?

Insert Field programmatically ( http://www.telerik.com/help/wpf/radrichtextbox-features-mail-merge.html ) is not answer on the question and it insert the field in the first line of the document. So I need user to select position of the picture as he can do it with normal text field.

Regards,
Saykor

2 Answers, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 05 Sep 2014, 12:37 PM
Hello Saykor,

For the field to be updated as a picture, you need to make sure its ImageUri property is set to the image path. For example, here is how to insert an InclduePictureField at the current caret position:
this.radRichTextBox.InsertField(new IncludePictureField() { ImageUri=uri });

Alternatively, you can use a merge field like in the example. For example you can subscribe to the CommandExecuting event of the control and check if the field that is being inserted should contain a photo.
void editor_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is InsertFieldCommand && e.CommandParameter is MergeField)
    {
        string fieldName = (e.CommandParameter as MergeField).PropertyPath;
 
        if ((e.CommandParameter as MergeField).PropertyPath.ToUpper() == "RECIPIENTPHOTO")
        {
            e.Cancel = true;
 
            MergeField mf = new MergeField();
            mf.PropertyPath = fieldName;
            IncludePictureField picField = new IncludePictureField();
            picField.SetPropertyValue(IncludePictureField.ImageUriProperty, mf);
            this.editor.InsertField(picField);
        }
    }
}

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Saykor
Top achievements
Rank 2
answered on 05 Sep 2014, 01:05 PM
Hi Petya
Thank you for your answer. It works with one small difference if we need picture to come from a stream not from uri.
                    //MergeField mf = new MergeField();
                    //mf.PropertyPath = fieldName;
                    IncludePictureField picField = new IncludePictureField();
                    picField.SetPropertyValue(IncludePictureField.ImageUriProperty, "Barcode");

And then we can subscribe to use StreamFromUriResolving event. Else the event not will be fire.
This is the answer on your question ( http://www.telerik.com/forums/image-merge-byte ) where you can't reproduce why StreamFromUriResolving is not firing. To fire the event you need {INCLUDEPICTURE Barcode} not {INCLUDEPICTURE {MERGEFIELD Barcode}}

Regards,
Tags
RichTextBox
Asked by
Saykor
Top achievements
Rank 2
Answers by
Petya
Telerik team
Saykor
Top achievements
Rank 2
Share this question
or