I develop text editor for the Windows store application (WinRT) based on RichEditBox control. RichEditBox use ITextParagraphFormat for paragraph operation and ListAlignment, ListLevelIndex and other properties for bulleted and numbered lists. I not found any samples to insert bulleted or numbered lists to RichEditBox. How I can to add lists to RichEditBox using ITextParagraphFormat?
You need to set the ITextParagraphFormat.ListType property for the ITextParagraphFormat. For bullet, set the ListType property to MarkerType.Bullet
, for number, set the ListType to MarkerType.Arabic
. More types please reference the MarkerType enumeration to choose other list types you want.
Here is a sample about adding the bullet and number to the selected paragraph list in the RichEditBox you can test.
XAML Code
<RichEditBox x:Name="Richbox" Height="400" Margin="40" >
</RichEditBox>
<Button x:Name="BtnSetbullet" Content="set bullet to richeditbox" Click="BtnSetbullet_Click"></Button>
<Button x:Name="BtnSetNumber" Content="set number to richeditbox" Click="BtnSetNumber_Click"></Button>
Code behind
private void BtnSetbullet_Click(object sender, RoutedEventArgs e)
{
Windows.UI.Text.ITextSelection selectedText = Richbox.Document.Selection;
ITextParagraphFormat paragraphFormatting = selectedText.ParagraphFormat;
paragraphFormatting.ListType = MarkerType.Bullet;
selectedText.ParagraphFormat = paragraphFormatting;
}
private void BtnSetNumber_Click(object sender, RoutedEventArgs e)
{
Windows.UI.Text.ITextSelection selectedText = Richbox.Document.Selection;
ITextParagraphFormat paragraphFormatting = selectedText.ParagraphFormat;
paragraphFormatting.ListType = MarkerType.Arabic;
selectedText.ParagraphFormat = paragraphFormatting;
}