Needed help in a Rich text box with bulleting option.
To achieve this my code is
<StackPanel Grid.Row="0" Orientation="Horizontal" x:Name="Stack">
<telerikRibbonBar:RadButtonGroup>
<telerikRibbonBar:RadRibbonToggleButton x:Name="Bullet" Click="Bullet_Click" Content="."/> </telerikRibbonBar:RadButtonGroup>
</StackPanel>
<telerik:RadRichTextBox x:Name="RTB" Height="300" Grid.Row="1" Width="600"/>
And in class file
private void Bullet_Click(object sender, RoutedEventArgs e)
{
RadDocument document = new RadDocument();
document = RTB.Document.Selection.CreateDocumentFromSelection();
RTB.Document.Selection.AnchorSelectionPositions();
document = CreateDocumentWithMultiLevelList(document);
RTB.Document = document;
}
And
private RadDocument CreateDocumentWithMultiLevelList(RadDocument document)
{
Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
BulletedList bulletList = new BulletedList(document);
bulletList.Style = DefaultListStyles.Numbered;
foreach (Paragraph paragraph in document.EnumerateChildrenOfType<Paragraph>())
{
bulletList.AddParagraph(paragraph);
}
document.Sections.Add(section);
return document;
}
The problem is that my code is replacing not only the selected text but the entire content of the Rich text block with my formatted text. Can I replace only the selected content by my new bulleted content?
To achieve this my code is
<StackPanel Grid.Row="0" Orientation="Horizontal" x:Name="Stack">
<telerikRibbonBar:RadButtonGroup>
<telerikRibbonBar:RadRibbonToggleButton x:Name="Bullet" Click="Bullet_Click" Content="."/> </telerikRibbonBar:RadButtonGroup>
</StackPanel>
<telerik:RadRichTextBox x:Name="RTB" Height="300" Grid.Row="1" Width="600"/>
And in class file
private void Bullet_Click(object sender, RoutedEventArgs e)
{
RadDocument document = new RadDocument();
document = RTB.Document.Selection.CreateDocumentFromSelection();
RTB.Document.Selection.AnchorSelectionPositions();
document = CreateDocumentWithMultiLevelList(document);
RTB.Document = document;
}
And
private RadDocument CreateDocumentWithMultiLevelList(RadDocument document)
{
Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
BulletedList bulletList = new BulletedList(document);
bulletList.Style = DefaultListStyles.Numbered;
foreach (Paragraph paragraph in document.EnumerateChildrenOfType<Paragraph>())
{
bulletList.AddParagraph(paragraph);
}
document.Sections.Add(section);
return document;
}
The problem is that my code is replacing not only the selected text but the entire content of the Rich text block with my formatted text. Can I replace only the selected content by my new bulleted content?