Table of contents with hierarchical chapter numbers

3 posts, 1 answers
  1. Björn
    Björn avatar
    6 posts
    Member since:
    Feb 2008

    Posted 17 Mar Link to this post

    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. Answer
    Boby
    Admin
    Boby avatar
    595 posts

    Posted 22 Mar Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Boby
    Admin
    Boby avatar
    595 posts

    Posted 22 Mar Link to this post

    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.
Back to Top