RichTextBox - MailMerge how to add INCLUDEPICTURE field from UI

3 posts, 1 answers
  1. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 02 Sep 2014 Link to this post

    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. Answer
    Petya
    Admin
    Petya avatar
    975 posts

    Posted 05 Sep 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 05 Sep 2014 Link to this post

    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,
Back to Top