Skip to content

Latest commit

 

History

History
77 lines (58 loc) · 5.08 KB

File metadata and controls

77 lines (58 loc) · 5.08 KB

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)