Hello Mihail,
I think the problem has something to do with inserting the field with FieldDisplayMode = "Result" instead of "Code". Please see the following project which demonstrates the two methods:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using Telerik.Windows.Documents.Model;
namespace SilverlightApplication70
{
public partial class MainPage : UserControl
{
public MyDataContext dc = new MyDataContext();
public MainPage()
{
InitializeComponent();
dc.Items = new List<
MyDataObject
>()
{
new MyDataObject()
{
TextProperty = "START1\nLorem ipsum dolor sit amet, consectetur adipiscing elit.\nMauris sit amet risus elit.\nDonec ullamcorper aliquam elit commodo accumsan.\nEND1"
},
new MyDataObject()
{
TextProperty = "START2\nVivamus dapibus varius augue non rutrum.\nMorbi in iaculis mauris.\nEND2"
},
new MyDataObject()
{
TextProperty = "START3\nDonec congue sagittis libero, commodo imperdiet leo tempus a.\nEND3"
},
};
this.DataContext = dc;
this.rtb1.Document.MailMergeDataSource.ItemsSource = dc.Items;
this.rtb3.Document.MailMergeDataSource.ItemsSource = dc.Items;
}
private void btn_InsertAsCode(object sender, RoutedEventArgs e)
{
this.rtb1.ActiveDocumentEditor.InsertField
(
new MergeField()
{
PropertyPath = "TextProperty"
},
FieldDisplayMode.Code
);
}
private void btn_Merge(object sender, RoutedEventArgs e)
{
this.rtb2.Document = this.rtb1.MailMergeCurrentRecord();
}
private void btn_InsertAsResult(object sender, RoutedEventArgs e)
{
this.rtb3.ActiveDocumentEditor.InsertField
(
new MergeField()
{
PropertyPath = "TextProperty"
},
FieldDisplayMode.Result
);
}
}
public class MyDataObject
{
public string TextProperty
{
get;
set;
}
}
public class MyDataContext : INotifyPropertyChanged
{
private List<
MyDataObject
> _Items;
public List<
MyDataObject
> Items
{
get
{
return _Items;
}
set
{
_Items = value;
RaisePropertyChanged("Items");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName)
{
var propertyChanged = PropertyChanged;
if ((propertyChanged != null))
{
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}