Custom shape and MVVM

5 posts, 1 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Feb 2012

    Posted 15 Nov 2012 Link to this post

    Hi'
    I would like to use custom shapes together with MVVM. I have followed the online documentation regarding MVVM and RadDiagram:
    http://www.telerik.com/help/wpf/raddiagrams-howto-mvvm.html
    But I do not know how to create custom shapes when using MVVM - could you please provide an example?
    Thanks,
    Michael
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Nov 2012 Link to this post

    Hello Michael,

     It is possible to use Custom Shapes in MVVM scenario. Actually this is demonstrated in our MindMap and OrgChart samples. The key moments in this requirement are:
     1) Inherit the RadDiagramShapeBase and create custom Shape like in this help article
     2) Inherit the RadDiagram and override the following methods:

    protected override Telerik.Windows.Diagrams.Core.IShape GetShapeContainerForItemOverride(object item)
    {
        return ShapeSelector.GetShape(item);
    }
     
    protected override bool IsItemItsOwnShapeContainerOverride(object item)
    {
        return item is MindmapShapeBase;
    }

    The GetShapeContainerForItemOverride method is the place where you can return Custom Shape or default Shape depending on your ViewModel.
     3) Use Style Selector to return a Style depending on the type of the business object.

    You can find these steps implemented in the attached project as well. Kind regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    2 posts
    Member since:
    Feb 2012

    Posted 21 Nov 2012 Link to this post

    Thanks! Most helpful

    Michael
  5. Kavita
    Kavita avatar
    2 posts
    Member since:
    Apr 2013

    Posted 17 Apr 2013 Link to this post

    Hey!!

    I need to create a wpf diagram designer which consist multiple layers design (user can add layers according to need and can switch among layers and can also show/ hide layers) and each layer can have different diagram but they are party of single design. Now my question is that how we can create multiple layers like we have different layers in photoshop where layers are used to work on individual parts of an image while not affecting other parts. And the same thing I have to create in wpf diagram designer .....

  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 19 Apr 2013 Link to this post

    Hello Kavita,

    As Lancelot explained in this forum post, the RadDiagram don't provide layers out-of-the-box but you can easily create custom layers by applying different ZIndex settings on the different shapes. Once you create your layers of shapes, you can mark each shape in order to know the layer it belongs to (you can use DataBinding and business values to differentiate the layers and the shapes or simply use the Tag property of the shapes). Once you can tell the layer in which a shape belongs, you can traverse the RadDiagram shapes collection and find all shapes of a certain layer to hide or display them together.

    Please let us know if this information helps.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready