
Konstantin
Top achievements
Rank 1
Konstantin
asked on 13 Dec 2018, 12:23 PM
Hello.
I am testing a WPF Org Chart Diagram and I need to dynamic create child nodes when user clicks the Node (lazy loading).
But I have a problem. When I create new node and link and call diagram.Layout(...), routing is corrupted.
How to fix it?
3 Answers, 1 is accepted
0

Konstantin
Top achievements
Rank 1
answered on 14 Dec 2018, 07:53 AM
To better understand my problem I show some code:
public
class
MainWindowViewModel : ViewModelBase
{
public
event
EventHandler<EventArgs> OnNodeAdded;
public
ICommand AddNodeCommand {
get
;
private
set
; }
public
Node RootNode {
get
;
private
set
; }
public
MainWindowViewModel()
{
AddNodeCommand =
new
RelayCommand(AddNodeExecute);
this
.GraphSource =
new
GraphSource();
_populateWithData();
}
public
void
AddNodeExecute(
object
parameter)
{
Node newVertex =
new
Node() { Text =
"Mary Bird"
};
RootNode.Children.Add(newVertex);
this
.GraphSource.AddNode(newVertex);
this
.GraphSource.AddLink(
new
Link(RootNode, newVertex));
//Notify View about new node is added
OnNodeAdded?.Invoke(
this
, EventArgs.Empty);
}
private
void
_populateWithData()
{
RootNode =
new
Node() { Text =
"Andrew Fuller"
};
Node level1 =
new
Node() { Text =
"Jeremy Boather"
};
level1.Children.Add(
new
Node() { Text =
"Steven Buchanan"
});
RootNode.Children.Add(level1);
RootNode.Children.Add(
new
Node() { Text =
"Anne Dodsworth"
});
RootNode.Children.Add(
new
Node() { Text =
"Robert King"
});
this
.GraphSource.PopulateGraphSource(RootNode);
}
private
GraphSource graphSource;
public
GraphSource GraphSource
{
get
{
return
this
.graphSource;
}
set
{
if
(
this
.graphSource != value)
{
this
.graphSource = value;
this
.OnPropertyChanged(
"GraphSource"
);
}
}
}
}
After new node was added, then ViewModel rise the Event "OnNodeAdded" and calling method of the View
private
void
MainWindowViewModel_OnNodeAdded(
object
sender, EventArgs e)
{
LayoutOrgChart(
true
);
}
0
Accepted
Hello Konstantin,
I've plugged your code into the OrgChart SDK example, but I wasn't able to reproduce the issue. Can you please check the attached project and let me know if I am missing something? Note that in order to add a new node you will need to press the right mouse button.
Regards,
Martin Ivanov
Progress Telerik
I've plugged your code into the OrgChart SDK example, but I wasn't able to reproduce the issue. Can you please check the attached project and let me know if I am missing something? Note that in order to add a new node you will need to press the right mouse button.
Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0

Konstantin
Top achievements
Rank 1
answered on 18 Dec 2018, 12:28 PM
Thank you, Matrin!
I have already solved my problem.
I began to use diagram.LayoutAsync() instead off Layout()