Articles in this section
Category / Section

How to modify stencil's symbol template dynamically at run time in WPF Diagram(SfDiagram)?

1 min read

WPF Diagram (SfDiagram) supports user to modify the Stencil’s symbol template dynamically at run time without affecting the selected filter’s state. For example, if we would like to switch Stencil’s symbols between two different formats like Text below the shape and Text beside the shape which can done easily by modifying the shape’s ContentTemplate or SymbolTemplate.

Please find the sample and code snippet as follows.

C#

private void TextBelowImgae_Click(object sender, RoutedEventArgs e)
{
    if (stencil.SymbolSource != null)
    {
        foreach (var item in stencil.SymbolSource as IEnumerable<object>)
        {
            if (item is NodeViewModel && (item as NodeViewModel).Name == "DiamondNode")
            {
                (item as NodeViewModel).UnitWidth = 100;
                (item as NodeViewModel).ContentTemplate = this.Resources["DiamondTextBelowImage"] as DataTemplate;
            }
 
            if (item is NodeViewModel && (item as NodeViewModel).Name == "TriangleNode")
            {
                (item as NodeViewModel).UnitWidth = 100;
                (item as NodeViewModel).ContentTemplate = this.Resources["TriangleTextBelowImage"] as DataTemplate;
            }
        }
    }
}

View the complete sample in GitHub

Take a moment to peruse the documentation, where you can find complete stencil control and its elements with code examples.

Refer here to explore the rich set of Syncfusion Essential SfDiagram features.

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied