Insert list in RichEditBox for Windows store application

那年仲夏 提交于 2019-12-08 10:04:31

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/39318252/insert-list-in-richeditbox-for-windows-store-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!