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

RadRichTextBox Rtf append

1 Answer 179 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 06 Dec 2011, 10:02 PM
Hi,

I'm using Telerik 2011.3.1116.35 and VS2008 with a RadRichtextBox. Actually I use a RtdDataProvider to add Rtf document in my RadRichTextBox.

When I try to insert new text at the end of my RadRichTextBox, the new text seems to clear the current content of my RadRichTextBox bedfore insert my new text.

Here is the xaml:
<Window x:Class="WpfApplication3.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:telerikProvider="clr-namespace:Telerik.Windows.Documents.FormatProviders.Rtf;assembly=Telerik.Windows.Documents.FormatProviders.Rtf"
    Title="Window1" Height="300" Width="641">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
              
        <StackPanel Orientation="Horizontal" DataContext="{Binding ElementName=editor, Path=Commands}">
            <telerik:RadRibbonToggleButton Text="B" FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleBoldCommand}" />
            <telerik:RadRibbonToggleButton Text="I" FontFamily="Times New Roman" FontSize="14" FontStyle="Italic" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleItalicCommand}" />
            <telerik:RadRibbonToggleButton FontFamily="Times New Roman" FontSize="14" telerik:RadRichTextBoxRibbonUI.RichTextCommand="{Binding Path=ToggleUnderlineCommand}">
                <Underline>U</Underline>
            </telerik:RadRibbonToggleButton>
            <telerik:RadButton Click="RadButton_Click">Test</telerik:RadButton>
        </StackPanel>
       
        <telerik:RadRichTextBox Grid.Row="1" x:Name="editor" Margin="24 24 0 0" AllowDrop="True" ShowComments="True" IsSelectionMiniToolBarEnabled="False" IsContextMenuEnabled="False" />       
        <telerikProvider:RtfDataProvider Name="Rtf" RichTextBox="{Binding ElementName=editor}" />
        <telerik:DocumentRuler AssociatedRichTextBox="{Binding ElementName=editor, Mode=OneTime}" Grid.Row="1" />
        <telerik:RadRichTextBoxStatusBar Grid.Row="2" AssociatedRichTextBox="{Binding ElementName=editor, Mode=OneTime}" />
    </Grid>
</Window>

Here is the code-behind:

using

 

System;

 

using

 

System.Collections.Generic;

 

using

 

System.Linq;

 

using

 

System.Text;

 

using

 

System.Windows;

 

using

 

System.Windows.Controls;

 

using

 

System.Windows.Data;

 

using

 

System.Windows.Documents;

 

using

 

System.Windows.Input;

 

using

 

System.Windows.Media;

 

using

 

System.Windows.Media.Imaging;

 

using

 

System.Windows.Navigation;

 

using

 

System.Windows.Shapes;

 

using

 

VPlayer;

 

using

 

Telerik.Windows.Documents.Model.Styles;

 

namespace

 

WpfApplication3

 

{

 

/// <summary>

 

 

/// Interaction logic for Window1.xaml

 

 

/// </summary>

 

 

public partial class Window1 : Window

 

{

 

public Window1()

 

{

InitializeComponent();

}

 

private void RadButton_Click(object sender, RoutedEventArgs e)

 

{

Rtf.Rtf =

"Line 1";

 

editor.Document.CaretPosition.MoveToLastPositionInDocument();

editor.Insert(

@"Line 2");

 

}

}

}


Thank's

1 Answer, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 08 Dec 2011, 06:46 PM
Hello Oliver,

The cause of the issue is this line:

Rtf.Rtf = "Line 1";

This will force the RtfDataProvider to create new RadDocument form the string "Line 1". As this is not valid Rtf string, an empty document is created and used in the RadRichTextBox control. The code after that just inserts the string "Line 2" in the newly created empty document. If you pass a valid RTF content (for example @"{\rtf1 Line 1}") everything works fine.

You can use TxtDataProvider if you want to pass just plain text to the data provider. 
Greetings,
Alex
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Oliver
Top achievements
Rank 1
Answers by
Alex
Telerik team
Share this question
or