Styling Shapes When Using GraphSource
This article describes which styles need to be applied when using a different ActiveTool of the RadDiagram when the GraphSource property is set.
For the purpose of this example, we will create the following ViewModels:
ContainerModel: A class deriving from the ContainerNodeViewModelBase ViewModel that represents a container node.
Model: A class deriving from the NodeViewModelBase ViewModel that represents a node.
Link: A class deriving from the LinkViewModelBase ViewModel that represents a link.
MyGraphSource: A class deriving from the ObservableGraphSourceBase ViewModel that represents the RadDiagram GraphSource.
Example 1: Creating the ViewModels
Next, we can go ahead and define a RadDiagram control in our view. We can add three buttons to change the ActiveTool property of the RadDiagram at runtime.
Example 2: Defining RadDiagram in XAML
Example 3: Setting GraphSource property
Note that CustomShapes is the name of the project used in the example and this will be different on your end.
You can observe that the container and the shape inside does not show our custom text. By clicking on any of the buttons (without PointerTool) at the top you can see that every created shape displays the respective NodeViewModelBase class string.
The different active tools correspond to different shapes:
- TextTool: Creates a RadDiagramTextShape
- PathTool: Creates a RadDiagramShape
- PencilTool: Creates a RadDiagramShape
- ConnectorTool: Creates a RadDiagramConnection
To overcome this you can create a StyleSelector and apply it to the ShapeStyleSelector of the RadDiagram. Example 4 demonstrates the custom StyleSelector.