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
0
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:
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
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
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
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.