1

我已经设法应用项目符号列表格式,但如何再次删除它?如何检测选择是否/包含一个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 的许多方面似乎设计得很糟糕......

4

2 回答 2

0

尝试EditingCommands.ToggleBullets.Execute(null, richTextBox)在选定段落中切换项目符号样式。

于 2015-03-12T13:56:26.140 回答
0

如果您可以使用 windows 窗体版本的 Richtextbox,则可以使用该SelectionBullet属性。

http://msdn.microsoft.com/en-us/library/ms742875.aspx

于 2013-10-28T14:52:00.863 回答