GithubHelp home page GithubHelp logo

devexpress-examples / wpf-diagram-create-diagramshape-descendant-with-editable-and-serializable-properties Goto Github PK

View Code? Open in Web Editor NEW
0.0 56.0 0.0 120 KB

Serialize and allow users to edit custom properties of DiagramShape descendants.

License: Other

C# 51.90% Visual Basic .NET 48.10%
dotnet dxdiagram wpf xpf

wpf-diagram-create-diagramshape-descendant-with-editable-and-serializable-properties's Introduction

WPF Diagram - Create a DiagramShape Descendant with Editable and Serializable Properties

This example demonstrates how to serialize and allow users to edit custom properties of DiagramShape descendants. In the example, the DiagramShapeEx class contains the serializable Description property. Users can edit this property value in the Properties Panel.

image

Implementation Details

  1. Mark your custom properties with the XtraSerializableProperty attribute to enable their serialization:

    public class DiagramShapeEx : DiagramShape {
        [XtraSerializableProperty]
        public string Description { get; set; }
        static DiagramShapeEx() {
            DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx));
        }
    }

    Make sure that your descendant class has a parameterless constructor.

  2. Call the DiagramItemTypeRegistrator.Register method to register your descendant type and allow its serialization. You should register descendants at the application startup. If the custom item is used in the Diagram Designer or Item Template Designer, it is necessary to also register it in the item static constructor:

    DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx));
  3. Create and register a FactoryItemTool that creates your custom shape when a user adds it to the canvas:

    var stencil = new DiagramStencil("CustomStencil", "Custom Shapes");
    var itemTool = new FactoryItemTool(
        "CustomShape",
        () => "Custom Shape", diagram => {
            DiagramShapeEx customShape = new DiagramShapeEx() { Width = 100, Height = 50 };
            return customShape;
        },
        new Size(100, 50),
        false
    );
    stencil.RegisterTool(itemTool);
    DiagramToolboxRegistrator.RegisterStencil(stencil);
  4. To allow users to edit your custom property in the Properties Panel, handle the DiagramControl.CustomGetEditableItemProperties event:

    private void diagramControl_CustomGetEditableItemProperties(object sender, DiagramCustomGetEditableItemPropertiesEventArgs e) {
        if (e.Item is DiagramShapeEx) {
            e.Properties.Add(TypeDescriptor.GetProperties(typeof(DiagramShapeEx))["Description"]);
        }
    }

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)

wpf-diagram-create-diagramshape-descendant-with-editable-and-serializable-properties's People

Contributors

alexgoon avatar alexilia avatar andreyslabov avatar devexpressexamplebot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

alexgoon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.