Please show an example of adding a label to a palette symbol in a diagram control?

Hi,

Your team reference using symbol description in another post, https://www.syncfusion.com/forums/154206/how-to-add-a-label-to-a-palette-symbol-in-a-diagram-control but how do you use it? Some example code would be nice. 

I want to have the student's name showing in a list to drag and drop into the diagram. The only thing I am missing is the name showing in the symbol palette. How can I do this?




3 Replies

GG Gowtham Gunashekar Syncfusion Team September 13, 2021 12:15 PM UTC

Hi Simon, 
 
Please refer to the following sample for how to add the description to the symbols in symbol palette. In the sample we have used the GetSymbolInfo to map the symbols id as the description to the symbols. We have added the documentation link for adding symbol description for symbols in the palette for your references.  
 
 
Code snippet: 
 <SfSymbolPaletteComponent @ref="@symbolpalette" Height="300px" Width="200px" GetSymbolInfo="GetSymbolInfo"> 
</SfSymbolPaletteComponent> 
 
   private SymbolInfo GetSymbolInfo(IDiagramObject symbol) 
    { 
        SymbolInfo SymbolInfo = new SymbolInfo(); 
        string text = null; 
        text = (symbol as Node).ID; 
        SymbolInfo.Description = new SymbolDescription() { Text = text }; 
        return SymbolInfo; 
    } 
 
 
Regards, 
Gowtham 



SI Simon replied to Gowtham Gunashekar September 13, 2021 01:47 PM UTC

Thanks, that worked a treat!

        protected SymbolInfo GetSymbolInfo(IDiagramObject symbol)
        {
            SymbolInfo SymbolInfo = new SymbolInfo();
            string text = (symbol as Node).Annotations.FirstOrDefault().Content;
            SymbolInfo.Description = new SymbolDescription() { Text = text };
            return SymbolInfo;
        }




GG Gowtham Gunashekar Syncfusion Team September 14, 2021 01:12 PM UTC

Hi Simon, 
 
Thanks for your update. Please let us know whether you need any further assistance on this. 
 
 
Regards  
Gowtham 


Loader.
Up arrow icon