We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding to non hierarhical data

Thread ID:

Created:

Updated:

Platform:

Replies:

117640 Nov 20,2014 06:17 PM UTC Nov 21,2014 11:35 AM UTC WPF 1
loading
Tags: Diagram
zzz
Asked On November 20, 2014 06:17 PM UTC

Hi there,
My model seems very easy:

public class State
{
    public string Name {get; set;}

    public State(string name)
    { Name= name;}
}

public class Transition
{
    public string Name {get; set;}
    public State Source{ get; set;}
    public State Target {get; set;}
   
    public Transition(string name, State source, State target)
    {
        Name = name;
        Source = source;
        Target = target;
    }
}
public class DiagrammViewModel
{
    public ObservableCollection<State> States{get; set;}
    public ObservableCollection<Transition> Transitions{get; set;}
    public DiagrammViewModel(IEnumerable<State> states, IEnumerable<Transition> transitions)
    {
        States = new ObservableCollection<State>(states);
        Transitions = new ObservableCollection<Transition>(transitions);
    }
}


And I I create data:
var idle = new State("Idle");
var running = new State("Running");
var stopping = new State("Stopping");
var stopped = new State("Stopped");
var holding = new State("Holding");
var held = new State("Held");

var run = new Transition("Run", idle, running);
var stop = new Transition("Stop", running, stopping);
var stopped = new Transition("", stopping, stopped);
var reset = new Transition("Reset", stopped, idle);
var hold = new Transition("Hold", running, holding);
var holdingHeld = new Transition("", holding, held);
var diagrammViewModel = new DiagrammViewModel(states, transitios);

It seems like this:
https://yadi.sk/i/k0vQeJymcWQNK

I want to bind this data to diagramModel, but I can`t bind directly to Nodes and Connections properties
And if I bind diagramModel to State collection, I recive flat diagram without any connection.
How can I do it?
There are only hierarhical data binding  in samples that distributed with essential studio
Now I fill Nodes and Collections prorerties of DiagrammModel via code, but it cause inconvenience
P.S. Sorry for my English:)
 



Saranya Chandrasekaran [Syncfusion]
Replied On November 21, 2014 11:35 AM UTC

Hi zzz,

We have analyzed about your requirement “Diagram using Nonhierarchical data with ItemSource”. This can be achieved in Diagram WPF with manual Layout (ItemSource for Node) and utility for Connectors in Application level.

Node and connector property of diagram is read-only, items cannot be added or removed from it, but it cannot be assigned with a new collection.

We have ItemsSource property that supports data-binding, we can do two things using this property.

1. A collection of business object can be assigned to it, a view (Node) will be generated for each business object.

2. When a hierarchy of objects (nested collection) are assigned, based on HierarchicalDataTemplate, a tree will be generated based on the parent child relationship.

So, using 1st approach, Node can generated through databinding through ItemSource property.

But, connector cannot be binded with items source. But we can work around this binding with a utility class in application level.

Suggestion:
Your requirement can be achieved in application level by deriving the DiagramControl and providing two properties for binding your Data. But, adding/removing of the Node and Connector based on the given data should be handled manually in application level.

Please let us know if you have further assistance on this.

Regards,
Saranya C


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;