DiagramItem ultimately derives from the Control class, and so diagram items can be styled and templated. For example, you can define the following style in a ResourceDictionary inside the page xaml:
XAML
![]() |
---|
<Style x:Key="MyNodeStyle" TargetType="unidiagram:ShapeNode"> |
Then you can assign the style to a new node as shown in this example:
C#
![]() |
---|
var node = new ShapeNode(); |
At the time of writing this, nodes that are created interactively have some local values set for their dependency properties, since they are initialized from the Diagram default-value properties such as ShapeBrush. To apply a style to such nodes, you might have to clear their local values first:
C#
![]() |
---|
private void OnNodeCreated(object sender, NodeEventArgs e) |
Using styles, it is also possible to define new control templates for diagram nodes. For example the code below defines a more light-weight template for ShapeNode objects:
XAML
![]() |
---|
<Style x:Key="MyNodeTemplate" TargetType="unidiagram:ShapeNode"> <Path x:Name="Shape" <TextBlock </Canvas> |
The DiagramItem class also defines two visual state groups. The group SelectionStates contains the Unselected and Selected states. The MouseStates group contains the MouseOut, MouseOver and MouseDown states. Note that the control does not provide any built-in animations for transitions between these states. If that's required, it can be implemented through custom Xaml templates where Storyboard objects are associated with states through the VisualStateManager.VisualStateGroups property. For example, in a node template defines a named UI element called "rect", its color can be animated when a node is selected as shown below:
XAML
![]() |
---|
<VisualStateManager.VisualStateGroups> |