Articles in this section
Category / Section

How to modify stencil's symbol template at run time in WPF Diagram?

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.

Conclusion

I hope you enjoyed learning about how to modify stencil's symbol template at run time in WPF Diagram.

 You can refer to our WPF Diagram feature tour  page to know about its other groundbreaking feature representations. You can also explore  documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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