如果我为 TextElement 属性的打开和关闭设置了一个按钮,则效果很好 - 根据此示例,对于选定的文本或仅在键入文本时打开或关闭。
Private Sub TextEditor_SwitchItalics(sender As Object, e As RoutedEventArgs)
Try
Dim vEditor As RichTextBox = TextEditorGrid.FindName("Controls_TextEditorRTF")
With vEditor
Select Case vEditor.Selection.GetPropertyValue(TextElement.FontStyleProperty)
Case FontStyles.Normal
vEditor.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Italic)
Case FontStyles.Italic
vEditor.Selection.ApplyPropertyValue(TextElement.FontStyleProperty, FontStyles.Normal)
End Select
End With
Catch ex As Exception
EmailError(ex)
End Try
End Sub
使用 TextDecorations 我遇到了问题 - 我可以打开,也可以关闭选定的文本,但尝试取消选择,因为打字没有效果。关于如何解决这个问题的任何想法?谢谢
Private Sub TextEditor_SwitchStrikethrough(sender As Object, e As RoutedEventArgs)
Try
Dim vEditor As RichTextBox = TextEditorGrid.FindName("Controls_TextEditorRTF")
Dim SelectionRange As New TextRange(vEditor.Selection.Start, vEditor.Selection.End)
If (SelectionRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Strikethrough)) Then
For Each Item In TextDecorations.Strikethrough
vEditor.Selection.ClearAllProperties()
Next
Else
vEditor.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Strikethrough)
End If
Catch ex As Exception
EmailError(ex)
End Try
End Sub