This is a migrated thread and some comments may be shown as answers.

Table of contents with hierarchical chapter numbers

2 Answers 11 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Björn
Top achievements
Rank 2
Björn asked on 17 Mar 2016, 06:10 AM

Hi,

I try to create a document (with the rich text editor UI, not by code) that contains a table of content which shows the heading numbers like in the attached sample from MS Word.

I'm using release 2015.1.401.40 of the WPF controls.

 

Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Boby
Telerik team
answered on 22 Mar 2016, 05:00 AM
Hello Björn,

Actually this list template is currently not added to the UI. The request is already logged in our public feedback portal, where you can vote and track eventual progress:
Support for multilevel list templates for Heading/Chapters.

Regards,
Boby
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Boby
Telerik team
answered on 22 Mar 2016, 08:12 AM
Hello,

The best thing you can do for now is to create list associated to heading styles by code. It will however not show in the list styles gallery in the ribbon, and the numbering will not appear in the TOC. Sample code follows:
private void button1_Click(object sender, RoutedEventArgs e)
{
    ListStyle listStyle = CreateHierarchicalListStyle();
 
    for (int i = 0; i < 9; i++)
    {
        ListLevelStyle listLevel = listStyle.Levels[i];
        listLevel.HangingIndent = 0;
        listLevel.Indent = 0;
        listLevel.StyleName = RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(i + 1);
    }
 
    DocumentList documentList = new DocumentList(listStyle, this.radRichTextBox.Document);
 
    for (int i = 0; i < 9; i++)
    {
        string headingStyleName = RadDocumentDefaultStyles.GetHeadingStyleNameByIndex(i + 1);
 
        StyleDefinition headingStyle = this.radRichTextBox.Document.StyleRepository.GetValueOrNull(headingStyleName);
 
        headingStyle.ParagraphStyle.ListId = documentList.ID;
        headingStyle.ParagraphStyle.ListLevel = i;
    }
}
 
private static ListStyle CreateHierarchicalListStyle()
{
    ListStyle listStyle = new ListStyle();
 
    for (int i = 0; i < ListStyle.ListLevels; ++i)
    {
        StringBuilder levelText = new StringBuilder();
        for (int j = 0; j < i + 1; ++j)
        {
            levelText.Append("{" + j + "}.");
        }
 
        listStyle.Levels.Add(new ListLevelStyle()
        {
            StartingIndex = 1,
            NumberingFormat = ListNumberingFormat.Decimal,
            LevelText = levelText.ToString(),
        });
    }
 
    return listStyle;
}


Regards,
Boby
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Björn
Top achievements
Rank 2
Answers by
Boby
Telerik team
Share this question
or