0

如果我为 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
4

1 回答 1

0

事实证明 ClearAllProperties 没有效果,但是将 TextDecorations 设置为 Nothing 有效

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.CaretPosition, vEditor.CaretPosition)
        If (SelectionRange.GetPropertyValue(Inline.TextDecorationsProperty).Equals(TextDecorations.Strikethrough)) Then
            For Each Item In TextDecorations.Strikethrough
                vEditor.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, Nothing)
                'vEditor.Selection.ClearAllProperties()
            Next
        Else
            vEditor.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Strikethrough)
        End If
    Catch ex As Exception
        EmailError(ex)
    End Try
End Sub
于 2013-07-29T14:26:06.580 回答