I am working on a solution to instantiate a DiagramViewModel loaded with a model prior to showing it on the UI. In my code, I instantiate the view model and pass in a file name. The goal is to load the xaml file and then pass the view model to the controller hosting the SFDiagram control. I have created the following code but the Info object is null thereby throwing an error.
How can I properly load a view model from the file? The only objects I can find that support loading model xaml from a file are the SFDiagram itself and the above IGraphInfo.
The overall goal is a MVVM pattern where I can pass a populated view model to a user control and then assign the Data Context from the view model to the SFDiagram control. Any assistance is very much appreciated.
Thank you for the reply and the samples. I have gone through them and while I understand you are recommending serializing and deserializing the diagram objects manually, I have some additional concerns. My diagrams will be very complex with connectors, dynamic ports, colors and custom decorators (see the screenshot for a sample). If I need to custom write all of that, it will be a massive undertaking. Especially since the SFDiagram.Save will handle all of this complexity already. I have used the SFDiagram.Save() and SFDiagram.Load() and it properly captures all of the complexities saving to a file and then reloading. I just need a way to leverage these methods from the View Model instead of from the control.
Hi Stephen,
Requirement : How to load model from file to View-Model
We have analysed your requirement. We could see that you are trying to load a file from the View-Model’s constructor itself. The value for View-Model's Info property will initiated only after its dependent diagram view is being loaded. So, we are requesting you to load file to View-Model once its dependent diagram view is loaded. We have created a simple sample in which we have added separate commands for performing Save and Load in the View-Model.
Please find the sample link as below,
If the given sample does not meet your requirement, then please let us know the purpose of loading diagrams file from the View-Model. We will try to achieve your requirement depending on your purpose.
Regards,
Deepa Thiruppathy