Skip to content

Create diagram items with custom elements and register these items in the toolbox

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-diagramcontrol-create-items-with-custom-content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF DiagramControl - Create Items with Custom Content

This example demonstrates how to create diagram items with custom elements and register these items in the toolbox.

image

DiagramControl shapes can display only string content. To add custom elements to diagram items, use DiagramContentItem objects with the specified ContentTemplate property:

<Style x:Key="formattedTextContentItem" TargetType="dxdiag:DiagramContentItem">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <!-- ... -->
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

Create a DiagramStencil object and call its RegisterTool method with the FactoryItemTool object as a parameter to register the created DiagramContentItem in the toolbox:

DiagramStencil stencil = new DiagramStencil("CustomTools", "Content Item Tools");

stencil.RegisterTool(new FactoryItemTool(
    id: "Text",
    getName: () => "Text",
    createItem: diagram => new DiagramContentItem() {
        CustomStyleId = "formattedTextContentItem"
    },
    defaultSize: new Size(230, 110), 
    isQuick: true
));

Call the DiagramToolboxRegistrator.RegisterStencil method to register the stencil:

DiagramToolboxRegistrator.RegisterStencil(stencil);

To deserialize the DiagramContentItem, specify its CustomStyleId property. This property accepts the applied style's key.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Create diagram items with custom elements and register these items in the toolbox

Topics

Resources

License

Stars

Watchers

Forks