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

Delete List Style

4 Answers 87 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
yiping
Top achievements
Rank 1
yiping asked on 27 Jun 2016, 03:10 PM

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);

4 Answers, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 30 Jun 2016, 12:00 PM
Hello ,

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 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.
0
yiping
Top achievements
Rank 1
answered on 06 Jul 2016, 11:57 AM
Thanks a lot. Problem solved.
0
yiping
Top achievements
Rank 1
answered on 12 Jul 2016, 01:04 PM

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?

0
Mihail
Telerik team
answered on 15 Jul 2016, 11:27 AM
Hello ,

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 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.
Tags
RichTextBox
Asked by
yiping
Top achievements
Rank 1
Answers by
Mihail
Telerik team
yiping
Top achievements
Rank 1
Share this question
or