I am trying to do MVVM with data binding to GraphSource using a ObservableGraphSourceBase. When I drop a container from the DiagramToolbox. How would be able to associate that container with view model item and still be able to undo or redo adding that item to the diagram?
We prepared a sample project for you which we hope can be a good starting Point. Basically, it is based on our MVVM sample in our XAML GutHub Reporistory. We added a DiagramToolBox in the sample. Please have in mind the following key points:
The GraphSource inherits from SerializableGraphSourceBase<NodeViewModelBase, Link> which is a type of ObservableGraphSourceBase which better supports Save / Load scenarios.
Brand inherits from ContainerNodeViewModelBase<object>. When you drop a container from the ToolBox, the diagram publishes DeserializeNode method in the SerializableGraphSourceBase and you can instatntiate an ssociate ViewModel:
public override NodeViewModelBase DeserializeNode(IShape shape, Telerik.Windows.Diagrams.Core.SerializationInfo info)
{
NodeViewModelBase node = null;
if (shape is IContainerShape)
{
node = new Brand();
}
Then it is automatically added to the GraphSource.
Please check out the application and let us know if you need further assistance. The following help article might also be worth reading. How To Serialize a DataBound Diagram
Petar Mladenov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely. Sign up for Free application insights >>