在 Windows 商店应用程序的 RichEditBox 中插入列表
Insert list in RichEditBox for Windows store application
我基于 RichEditBox 控件为 Windows 商店应用程序 (WinRT) 开发文本编辑器。
RichEditBox 使用 ITextParagraphFormat 进行段落操作,使用 ListAlignment、ListLevelIndex 和其他属性进行项目符号列表和编号列表。
我没有找到任何示例来将项目符号列表或编号列表插入到 RichEditBox。
如何使用 ITextParagraphFormat 将列表添加到 RichEditBox?
您需要设置 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 枚举来选择您想要的其他列表类型。
这是一个关于将项目符号和编号添加到您可以测试的 RichEditBox 中的选定段落列表的示例。
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;
}
我基于 RichEditBox 控件为 Windows 商店应用程序 (WinRT) 开发文本编辑器。 RichEditBox 使用 ITextParagraphFormat 进行段落操作,使用 ListAlignment、ListLevelIndex 和其他属性进行项目符号列表和编号列表。 我没有找到任何示例来将项目符号列表或编号列表插入到 RichEditBox。 如何使用 ITextParagraphFormat 将列表添加到 RichEditBox?
您需要设置 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 枚举来选择您想要的其他列表类型。
这是一个关于将项目符号和编号添加到您可以测试的 RichEditBox 中的选定段落列表的示例。
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;
}