|
Sl.No. |
Requirement |
Response |
|
1 |
I am having the hardest time trying to figure out how bind the ObservableCollection from my view model to create nodes dynamically. I do not want to do this in code behind - I would prefer to use bindings with my view model, which is an ObservableCollection that is updated (a query to WMI) upon pressing refresh. Please let me know how I can accomplish this? |
We have support to achieve the requirement. We have Provided sample to represent this.
Please refer the sample link as below.
Sample details:
We have created 4 NodeViewModel and added it to DiagramViewModel.Nodes property of type ObservableCollection<NodeViewModel>. This Nodes collection is binded with SfDiagram.Nodes collection in Xaml. Clicking on add button, will add a new node to DiagramViewModel.Nodes collection, which will be reflected in UI.
If our assumption is different from your requirement, please provide screenshot, sample or video to represent the requested requirement. |
|
2 |
The documentation is a bit overwhelming and I didn't see anything relevant to this case in there or the forums. |
As data binding is primary part of WPF, and it is supported for all dependency properties of diagram, it is not explicitly document. However, you can refer to Diagram Builder product showcase demo from WPF sample browser. It is built completely with MVVM pattern.
Please refer the sample location as below.
Location: EssentialStudio -> 15.4.0.17 -> WPF -> Showcase -> Diagram Builder |
|
Sl.No. |
sample code |
Modified sample code |
|
1 |
ObservableCollection<NodeViewModel> nodes = new ObservableCollection<NodeViewModel>(); |
ObservableCollection<Employee> nodes = new ObservableCollection<Employee>(); |
|
2 |
foreach (Employee result in results)
{
NodeViewModel nvm = new NodeViewModel();
nvm.Content = result;
nodes.Add(nvm);
} |
foreach (Employee result in results)
{
nodes.Add(result);
} |
|
3 |
diagramControl.Nodes = nodes; |
diagramControl.Nodes = new ObservableCollection<NodeViewModel>(); |