如果我为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发布于 2013-07-29 22:26:07
事实证明,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 Subhttps://stackoverflow.com/questions/17659910
复制相似问题