none
Bullet selection in RichTextBox

    Question

  • How do I bullet the text in a WPF RichTextBox like I used to do with Windows Forms Selection.Bullet. I am using the code below to set the font weight and colour of the selected text, how do I bullet the selected text.

    this.wndAppTextBox.Selection.Text += cf.getCommand (i).getName  () + "\r";
    this.wndAppTextBox.Selection.ApplyPropertyValue(RichTextBox.FontWeightProperty, "Bold");
    this.wndAppTextBox.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty, Brushes.BlueViolet);
                                
    Monday, October 12, 2009 6:08 PM

Answers

  • It seems that the only way you can bullet text is by using a List (System.Windows.Document.List) which I eventually found in the MSDN documentation.  It would be nice if someone could confirm this however.

    System.Windows.Documents.List cmndList = new System.Windows.Documents.List();   //create and initialise a Document Listfor application-specific and window specific commands
                cmndList.MarkerStyle = TextMarkerStyle.Box;                                     //set the marker style for the List
                for(int i = 0; i < 50; i++) {
                    Run nameRun = new Run(myObject.getName ());                            //add header
                    ListItem cmndItem = new ListItem(new Paragraph(nameRun));  //create a ListItem with the command
                    cmndList.ListItems.Add(cmndItem);                           //add the ListItem to the List                                        
                }
                myFlowDocument.Blocks.Add(cmndList);                    //add the List to the FlowDocument of the RichTextBox
                
    • Marked as answer by monkey8888z Tuesday, October 13, 2009 1:05 PM
    Tuesday, October 13, 2009 1:04 PM

All replies

  • Okay I have tried this a different way, I now have a RichTextBox with a FlowDocument and I am adding text line by line using the following code, how do I bullet each line? I have looked at the different properties for the Run, Paragraph and FlowDocument but I can't see any way of

    this.wndAppTextBox.Document.Blocks.Clear ();
                Paragraph cmndPar = new Paragraph();
                for (int i = 0; i < 100; i++)
                {
                    Run cmndRun = new Run(cf.getCommand(i).getName() + "\n");
                    cmndRun.Foreground = Brushes.BlueViolet;
                    Bold cmndBold = new Bold(new Run(cf.getCommand(i).getApp1() + "\n"));
                    cmndPar.Inlines.Add(cmndRun);
                    cmndPar.Inlines.Add(cmndBold);
                }
                myFlowDocument.Blocks.Add(cmndPar);
                

    doing it. Any help greatly appreciated.

    • Marked as answer by monkey8888z Tuesday, October 13, 2009 1:05 PM
    • Unmarked as answer by monkey8888z Tuesday, October 13, 2009 1:05 PM
    Monday, October 12, 2009 8:50 PM
  • It seems that the only way you can bullet text is by using a List (System.Windows.Document.List) which I eventually found in the MSDN documentation.  It would be nice if someone could confirm this however.

    System.Windows.Documents.List cmndList = new System.Windows.Documents.List();   //create and initialise a Document Listfor application-specific and window specific commands
                cmndList.MarkerStyle = TextMarkerStyle.Box;                                     //set the marker style for the List
                for(int i = 0; i < 50; i++) {
                    Run nameRun = new Run(myObject.getName ());                            //add header
                    ListItem cmndItem = new ListItem(new Paragraph(nameRun));  //create a ListItem with the command
                    cmndList.ListItems.Add(cmndItem);                           //add the ListItem to the List                                        
                }
                myFlowDocument.Blocks.Add(cmndList);                    //add the List to the FlowDocument of the RichTextBox
                
    • Marked as answer by monkey8888z Tuesday, October 13, 2009 1:05 PM
    Tuesday, October 13, 2009 1:04 PM
  • The alternative is to programmatically execute the EditingCommands.ToggleBullets command. You can manually see the effects of this command by doing Ctrl+Shift+L on the current selection.

    EditingCommands.ToggleBullets.Execute(null, myRichTextBox);

    Tuesday, October 13, 2009 4:37 PM