在Windows应用商店的RichEditBox中插入列表

问题描述:

我基于RichEditBox控件为Windows应用商店(WinRT)开发文本编辑器. RichEditBox将ITextParagraphFormat用于段落操作,将ListAlignment,ListLevelIndex和其他属性用于项目符号列表和编号列表. 我没有找到任何将项目符号或编号列表插入RichEditBox的示例. 如何使用ITextParagraphFormat将列表添加到RichEditBox?

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?

您需要设置 MarkerType 枚举以选择所需的其他列表类型.

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.

这里是有关将项目符号和编号添加到可以测试的RichEditBox中的选定段落列表中的示例.

Here is a sample about adding the bullet and number to the selected paragraph list in the RichEditBox you can test.

XAML代码

 <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>

后面的代码

 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;           
 }