Create Custom Image Bullets

Product Version Product Author
2020.1.316 RadPdfProcessing Martin Velikov

Description

How to create a custom ListLevel with custom bullets containing images.

Solution

This functionality could be achieved by creating a custom class implementing IBulletNumberingFormat and passing it to BulletNumberingFormat property of the ListLevel class.

RadFixedDocument document = new RadFixedDocument(); 
 
Table table = new Table(); 
TableRow firstRow = table.Rows.AddTableRow(); 
TableCell tableCell = firstRow.Cells.AddTableCell(); 
 
List list = this.GetCustomBullet(); 
 
Block block1 = tableCell.Blocks.AddBlock(); 
block1.SetBullet(list, 0); 
block1.InsertText("Sample block text 1"); 
 
Block block2 = tableCell.Blocks.AddBlock(); 
block2.SetBullet(list, 0); 
block2.InsertText("Sample block text 2"); 
 
Block block3 = tableCell.Blocks.AddBlock(); 
block3.SetBullet(list, 0); 
block3.InsertText("Sample block text 3"); 
 
RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document); 
editor.InsertTable(table); 

__ Create custom image numbering bullet

private List GetCustomBullet() 
{ 
    List list = new List(); 
 
    for (int i = 0; i < 3; i++) 
    { 
        ListLevel level = list.Levels.AddListLevel(); 
        level.ParagraphProperties.FirstLineIndent = -72; 
        level.ParagraphProperties.LeftIndent = 0; 
        int currentLevelIndex = i; 
 
        level.BulletNumberingFormat = new CustomBullet((indexer) => 
        { 
            Image image = new Image(); 
 
            for (int levelIndex = 0; levelIndex <= currentLevelIndex; levelIndex++) 
            { 
                image = new Image() { Width = 25, Height = 25 }; 
                using (Stream stream = new FileStream($"Images/Image{indexer.GetCurrentIndex(levelIndex)}.png", FileMode.Open)) 
                { 
                    image.ImageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(stream); 
                } 
            } 
 
            return image; 
        }); 
    } 
 
    return list; 
} 

__ Creating a custom class implementing IBulletNumberingFormat

internal class CustomBullet : IBulletNumberingFormat 
{ 
    private readonly Func<IListLevelsIndexer, Image> getBullet; 
 
    public CustomBullet(Func<IListLevelsIndexer, Image> getBullet) 
    { 
        this.getBullet = getBullet; 
    } 
 
    public PositionContentElement GetBulletNumberingElement(IListLevelsIndexer listLevelsIndexer) 
    { 
        Image positionContentElement = this.getBullet(listLevelsIndexer); 
        return positionContentElement; 
    } 
} 
In this article
Not finding the help you need? Improve this article