我似乎无法弄清楚如何在新的 RichTextBox 中进行选择对齐,我有一个想法,我需要将选择转换为支持对齐的段落类型,但似乎无法弄清楚这一点。Silverlight 示例中没有一个具有此功能,但我确信这是可能的。
我有这段代码,它不起作用 - 因为我认为我需要选择一个段落,因为它总是返回并且异常“值不在预期范围内”。
Editor.Selection.SetPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left)
我确保首先检查有效选择,如下代码适用于“粗体”:
If Editor.Selection.Text.Length > 0 Then ' Text Selected
If TypeOf Editor.Selection.GetPropertyValue(Run.FontWeightProperty) Is FontWeight _
AndAlso DirectCast(Editor.Selection.GetPropertyValue(Run.FontWeightProperty), FontWeight) = FontWeights.Normal Then
Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Bold)
Else
Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Normal)
End If
End If
Editor.Focus()
XAML 中的示例:
<Paragraph TextAlignment="Right">Example</Paragraph>
以上适用于 RichTextBox 的内容,但是我需要根据选择以编程方式执行此操作 - 就像在写字板中一样。