我已经设法应用项目符号列表格式,但如何再次删除它?如何检测选择是否/包含一个List
?我把事情复杂化了吗?有没有一种直接的方法可以将选择转换为项目符号列表并返回?
Private Sub bullet(o As Windows.Forms.ContextMenuStrip, e As Windows.Forms.ToolStripItemClickedEventArgs)
Dim lst As New Windows.Documents.List()
lst.MarkerStyle = bullets(e.ClickedItem.Text)
If rtf.Selection.IsEmpty Then
lst.ListItems.Add(New Windows.Documents.ListItem())
Else
Dim li As Windows.Documents.ListItem
Dim lines() As String = rtf.Selection.Text.Split(vbCrLf)
For Each s As String In lines
li = New Windows.Documents.ListItem()
li.Blocks.Add(New Windows.Documents.Paragraph(New Windows.Documents.Run(s.Trim())))
lst.ListItems.Add(li)
Next
rtf.Selection.Text = ""
End If
Dim curCaret = rtf.CaretPosition
Dim curBlock = rtf.Document.Blocks.Where(Function(x) x.ContentStart.CompareTo(curCaret) = -1 AndAlso x.ContentEnd.CompareTo(curCaret) = 1).FirstOrDefault()
rtf.Document.Blocks.InsertAfter(curBlock, lst)
Dim vMove As Windows.Documents.TextPointer = Nothing
vMove = curCaret.GetNextInsertionPosition(Windows.Documents.LogicalDirection.Forward)
If vMove IsNot Nothing Then rtf.CaretPosition = vMove
rtf.Focus()
End Sub
从那以后,我从我的项目中删除了这段代码,因为它在某些情况下不可靠。基于动态 XAML 插入的解决方案会更可靠吗?WPF 的许多方面似乎设计得很糟糕......