This is a migrated thread and some comments may be shown as answers.

Custom Shape Binding

6 Answers 94 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Egemen
Top achievements
Rank 1
Egemen asked on 01 Apr 2013, 08:58 PM
Hi,

I'd like to bind an ObservableCollection<CustomShape> to RadDiagram in Xaml like {Binding MyShapes}.Is it possible to do this?

6 Answers, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 05 Apr 2013, 12:33 PM
RadDiagram definitely supports MVVM, but  my understanding is that you have to bind to something derived from the GraphSourceBase<TNode, TLink> base class (or IGraphSource) .     You'll just need to transform your collection into the list of Nodes.

See this...
http://www.telerik.com/help/silverlight/raddiagrams-howto-mvvm.html
0
Egemen
Top achievements
Rank 1
answered on 15 Apr 2013, 12:55 PM
Hi,

Yes, i know this article but my custom shapes are already derived from RadDiagramShapeBase... When i tried to use IGraphSource,
i have an exception because i don't need to implement the methods about Links. I tried to implement a fake implementation but i had got some internal exceptions...

Thank you for your help.
0
Tina Stancheva
Telerik team
answered on 18 Apr 2013, 08:59 AM
Hello Egemen,

When working with MVVM it is best to follow its main concept - separate the UI from the business logic. And if you create a business collection of custom shapes that derive from RadDiagramShapeBase, then you're breaking this concept as the RadDiagramShapeBase is essentially an UIElement. And I believe this is why you've experienced issues with this approach.

And if your goal is to bind the RadDiagram GraphSource to a collection of business data, then the article Tom mentioned is the way to go. The GraphSource described in it uses NodeViewModelBase and LinkViewModelBase classes which are data classes that are designed to describe the nodes and links in a diagram. Then once you bind the RadDiagram.GraphSource to the business collection, it will automatically create RadDiagramShape/RadDiagramConnection objects to wrap the
NodeViewModelBase/LinkViewModelBase items. But if you need to wrap the NodeViewModelBase items in CustomShapes, then you have to create a custom RadDiagram. In the custom diagram class you need to override the IsItemItsOwnShapeContainerOverride and GetShapeContainerForItemOverride methods to return the custom shape type:
public class CustomDiagram : RadDiagram
{
    protected override bool IsItemItsOwnShapeContainerOverride(object item)
    {
        return item is CustomShape;
    }
 
    protected override Telerik.Windows.Diagrams.Core.IShape GetShapeContainerForItemOverride(object item)
    {
        return new CustomShape();
    }
}

This approach is described at the bottom of the How to Create Custom Shape article.

Kind regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Egemen
Top achievements
Rank 1
answered on 18 Apr 2013, 06:43 PM
Hi,

I haven't got any business data. My goal is just  to bind CustomShape collection in the XMAL like this {Binding MyShapes}. Tom mentioned that l just need to transform your collection into the list of Nodes.
Can you please tell me how i can do this ? Could you provide me an example please...

Thank you
0
Tina Stancheva
Telerik team
answered on 19 Apr 2013, 03:28 PM
Hello Egemen,

Please take a look at this forum post as it describes such a scenario.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Egemen
Top achievements
Rank 1
answered on 24 Apr 2013, 09:08 PM
Thank you very much for your help.
Tags
Diagram
Asked by
Egemen
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Egemen
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or