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 に答える