Hi,
I tried adding a node and a link to the GraphSource. It worked but after this operation, the diagram layout seems to have been reset even though the AutoLayout property is set to True.
MainWindow.xaml.cs
using System;
using System.Windows;
using radDiagramTest.ViewModels;
using Telerik.Windows.Diagrams.Core;
namespace radDiagramTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ClassificationGraphViewModel viewModel = RootGrid.Resources["ViewModel"] as ClassificationGraphViewModel;
ClassificationDiagram.GraphSource = viewModel?.GraphSource;
ClassificationDiagram.Loaded += ClassificationDiagram_Loaded;
ClassificationDiagram.AutoFit( new Thickness( 10 ), false );
}
private void ClassificationDiagram_Loaded( Object _sender, RoutedEventArgs _e )
{
TreeLayoutSettings settings = new TreeLayoutSettings
{
TreeLayoutType = TreeLayoutType.TreeDown,
HorizontalSeparation = 300d,
VerticalSeparation = 75d
};
settings.Roots.Add( ClassificationDiagram.Shapes[0] );
ClassificationDiagram.Layout( LayoutType.Tree, settings );
ClassificationDiagram.AutoLayout = true;
ClassificationDiagram.IsEditable = false;
}
}
}
NodeViewModel.cs (node custom view model where the Add button is)
using System;
using System.Windows;
using System.Windows.Input;
using radDiagramTest.ViewModels;
using Telerik.Windows.Controls.Diagrams.Extensions.ViewModels;
namespace radDiagramTest
{
public class NodeViewModel : HierarchicalNodeViewModel
{
public NodeViewModel( ClassificationGraphViewModel _parent )
{
m_Parent = _parent;
AddNodeCommand = new SimpleCommand( AddNodeCommandHandler );
}
public ICommand AddNodeCommand { get; set; }
public String Name { get; set; }
private void AddNodeCommandHandler()
{
NodeViewModel newNode = new NodeViewModel( m_Parent ) { Name = "New Node" };
m_Parent.GraphSource.AddNode( newNode );
LinkViewModel newLink = new LinkViewModel( this, newNode ) { Name = "New Edge" };
m_Parent.GraphSource.AddLink( newLink );
}
private readonly ClassificationGraphViewModel m_Parent;
}
}