I have an app where one view is a xamDiagram and toolbox allowing the user to create a workflow type diagram. I have two node types, each bound to a separate data type deriving from a "node" data type that I have defined. The item source for the XamDiagram is a collection of objects of the "node" data type. I am using two node definitions with their own node style where I can bind to the two derived types based on node type. This works well for everything but node position. Each node has a position property that I am setting as nodes are dropped or moved. Whenever I swap views by changing the ContentControl ContentTemplate in the main view, if I swap back to the view containing the XamDiagram, the nodes are all at position 0,0 on top of one another, despite the position property of each node in the item source collection still being set to the correct position. Is there a way to bind the nodes' position to the property in my classes so that the diagram will still reflect those positions when the view is changed? I can't do something like this: <Setter Property="Position" Value="{Binding Position}" /> in my NodeStyle since the binding will look for a position property in my view model rather than in the class that goes with the target type of the node.
Hello Jackson,
I had a look at your issue with xamdiagram nodes not maintaining their correct positions. The best way for us to assist you is if you provide a small isolated sample that we can run and use for debugging locally. If you are unable able to provide an isolated sample I may be able to give suggestions if you provide the code for your page.
Also, here is a link to our guide on configuring diagram nodes: https://www.infragistics.com/help/wpf/xamdiagram-configuring-the-position-and-size-of-diagram-nodes
I am trying to upload a zip file of a simplified app that shows what I'm talking about, but the site keeps giving an error when I click reply.
Try deleting the bin and obj folders to reduce the file size.
SampleViewChangeApp.zip
Here is a simplified version of my app. You can recreate the issue by dragging out some nodes from the toolbox, then going to "Views" in the top left and selecting "Other". Then go back to "Views" and select "Workflow" and the nodes are now repositioned stacked in the top left corner.
After looking it over the issue appeared to be in the binding since the regular binding applies to the view the binding was breaking when you changed views. I was able to fix this by using a relative source binding like below which you will see in the sample in the workflowview.xaml in the style setters for the position properties.
{Binding RelativeSource={RelativeSource Self}, Path=Content.Position}
SampleViewChangeAppFixed.zip