Delete List Style

5 posts, 0 answers
  1. yiping
    yiping avatar
    17 posts
    Member since:
    Nov 2015

    Posted 27 Jun Link to this post

    Is there any way to delete a custom list style?

    These commands seems not working and will create some null reference exception on next opening of manage styles dialog.

                    document.StyleRepository.Remove(listStyle.StyleLink);

                    document.ListManager.UnRegisterListStyle(numListStyle);

                    document.ListManager.UnRegisterListStyle(listStyle);

  2. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 30 Jun Link to this post

    Hello yiping,

    The methods you are referring to are not enough if you would like to remove the custom list. You will need also to make sure that the list is cleared from all paragraphs that it has been applied on. I have prepared a simple code example on how a custom list should be removed from a document:
    private void RemoveCustomListStyle(ListStyle listStyle, RadDocument document)
    {
        RemoveParagraphsFromList(listStyle, document);
     
        if (!string.IsNullOrEmpty(listStyle.StyleLink))
        {
            ListStyle mediatorList = document.ListManager.GetAllListStyles().Where(l => l.NumStyleLink == listStyle.StyleLink).FirstOrDefault();
     
            RemoveParagraphsFromList(mediatorList, document);
     
            document.ListManager.UnRegisterListStyle(mediatorList);
     
            StyleDefinition styleDefinition = document.StyleRepository.GetValueOrNull(listStyle.StyleLink, false);
            document.StyleRepository.Remove(styleDefinition);
        }
     
        document.ListManager.UnRegisterListStyle(listStyle);
    }
     
    private static void RemoveParagraphsFromList(ListStyle listStyle, RadDocument document)
    {
        DocumentList documentList = document.ListManager.GetAllDocumentLists().Where(dl => dl.Style == listStyle).FirstOrDefault();
     
        List<Paragraph> paragraphs = documentList.Paragraphs.ToList();
     
        foreach (var paragraph in paragraphs)
        {
            documentList.RemoveParagraph(paragraph);
            paragraph.ListId = Paragraph.ListIdProperty.DefaultValue.Value;
            paragraph.ListLevel = Paragraph.ListLevelProperty.DefaultValue.Value;
        }
    }


    Please have in mind that using the API in the RadDocument will not add this operation to the Undo stack. I have logged a feature request into our feedback portal for implementing commands for add and delete commands. Here is the link if you would like to subscribe for status changes: Implement add and delete list command.

    Regards,
    Mihail
    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. yiping
    yiping avatar
    17 posts
    Member since:
    Nov 2015

    Posted 06 Jul in reply to Mihail Link to this post

    Thanks a lot. Problem solved.
  5. yiping
    yiping avatar
    17 posts
    Member since:
    Nov 2015

    Posted 12 Jul Link to this post

    Hi Mihail,

    After running this code to remove an applied costum list style, the opening manage style dialog will throw a null reference exception. Could you please look into it?

  6. Mihail
    Admin
    Mihail avatar
    192 posts

    Posted 15 Jul Link to this post

    Hello yiping,

    I can confirm that there is an exception after removing the list style and trying to open the manage styles dialog.

    I am afraid that there is no workaround for this issue. Once we implement the Add and Delete list style commands the feature request item in our feedback portal will be updated. Here is the link: Implement add and delete list command

    Please excuse us for the inconvenience.

    Regards,
    Mihail
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready