Xaml:
<StackPanel>
_richTextBox.SetValue(Xceed.Wpf.Toolkit.RichTextBox.TextProperty, _richTextBox.TextFormatter.GetText(_richTextBox.Document));
_richTextBox.RaiseEvent(new System.Windows.RoutedEventArgs(System.Windows.UIElement.LostFocusEvent, _richTextBox));
It is ok now.
Sincerely Yours.
<StackPanel>
<xctk:RichTextBox x:Name="_richTextBox" Text="{Binding Path=Content,Mode=TwoWay}" Width="200"/>
<Button Content="Click Me" Click="Button_Click" />
</StackPanel>
Code-Behind:public partial class MainWindow : Window
{
private Book book;
public MainWindow()
{
InitializeComponent();
book = new Book();
this.DataContext = book;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
_richTextBox.Document.Blocks.Add(new Paragraph(new Run("english")));//statement 1
System.Diagnostics.Debug.WriteLine("Text is now : " + _richTextBox.Text);
}
}
public class Book: INotifyPropertyChanged {
private string content;
public string Content {
get
{
return content;
}
set
{
content = value;
OnPropertyChanged("Content");
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this,
new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
When we input some text from the interface,the book.Content gets changed immediately.While if we modify the Document from the code behind(statement 1),the Content doesn't change.If I put some code,like I have mentioned before, behind the statement 1 :_richTextBox.SetValue(Xceed.Wpf.Toolkit.RichTextBox.TextProperty, _richTextBox.TextFormatter.GetText(_richTextBox.Document));
_richTextBox.RaiseEvent(new System.Windows.RoutedEventArgs(System.Windows.UIElement.LostFocusEvent, _richTextBox));
It is ok now.
Sincerely Yours.