Themes with WPF Diagram (SfDiagram)

2 Mar 20223 minutes to read

Diagram themes are predefined sets of diagram item styles that can be applied easily to the diagram elements. In Diagram, nearly 20 Built-In themes are available. DiagramTheme has NodeStyles, ConnectorStyles, and Theme properties that can be used to create custom Diagram theme.

To know more about DiagramTheme properties, refer to the DiagramTheme.

Built-In Themes

Built-In themes are predefined themes inherited from DiagramTheme. Each Built-In themes has four variants. Based on the selected theme and variants, the style of the node and connector will be changed. By default, first variant style of the specified Built-In theme will be applied to the Diagram elements.

To Know more about Built-In themes, refer to Built-In.

To change the DiagramTheme,

<!--Resource Dictionary which contains predefined shapes for Node-->
    <ResourceDictionary Source="/Syncfusion.SfDiagram.Wpf;component/Resources/BasicShapes.xaml"/>

<!--Initialize the Sfdiagram-->
<syncfusion:SfDiagram x:Name="diagram">
//Instance of SfDiagram
SfDiagram diagram = new SfDiagram();
DiagramTheme theme = new OfficeTheme();
diagram.Theme = theme;

Variant Styles and ShapeStyles

Variant styles are set of styles that are applied to Diagram elements. Each variant style contains 46 shape styles. You can change the style of each node in the diagram using the ThemeStyleId property. Based on the values of theme and variant style, the style will be applied to the node.

To change the Variant and Style,

<!--Initialize the Sfdiagram-->
<syncfusion:SfDiagram x:Name="diagram">
        <!--Initialize the NodeCollection-->
            <!--Initialize the Node-->
            <syncfusion:NodeViewModel OffsetX="100" OffsetY="100" UnitWidth="75" UnitHeight = "75" Shape="{StaticResource Ellipse}" ThemeStyleId="Variant1">
diagram.Theme = new OfficeTheme();
NodeViewModel node = new NodeViewModel()
    OffsetX = 100,
    OffsetY = 100,
    UnitWidth = 75,
    UnitHeight = 75,
    Shape = App.Current.Resources["Rectangle"],
    //adding theme style ID as variant1.
    ThemeStyleId = StyleId.Variant1,

node.Annotations = new ObservableCollection<IAnnotation>()
    new TextAnnotationViewModel()
        Text = node.ThemeStyleId.ToString(),
        TextWrapping = TextWrapping.Wrap,

(diagram.Nodes as ObservableCollection<NodeViewModel>).Add(node);

Diagram themes

View Sample in GitHub.