private void RecreateGraph(NodeGraphBehavior behavior) { // Disconnect all controls foreach (var node in AssociatedObject.VertexList) { // Disconnect control node.Key.DisconnectControl(node.Value); } // Loop through all the root nodes and add them behavior.graph.Clear(); AssociatedObject.RemoveAllEdges(); AssociatedObject.RemoveAllVertices(); if (behavior.Vertices != null && behavior.Edges != null) { foreach (var item in behavior.Vertices) { AddNode(item as NodeVertex); } foreach (var item in behavior.Edges) { AddEdge(item as NodeEdge); } } }
/// <summary> /// /// </summary> private void Register() { // graph_area_ = AssociatedObject; // Find the graph behavior graphBehavior = Interaction.GetBehaviors(graph_area_).OfType <NodeGraphBehavior>().FirstOrDefault(); if (graphBehavior != null) { graphBehavior.VerticesCollectionChanged += GraphBehavior_VerticesCollectionChanged; graphBehavior.EdgesCollectionChanged += GraphBehavior_EdgesCollectionChanged; } // Travel up the visual tree and get the zoom control // If the zoom control doesn't exist, then we can't use this behavior // TODO: Done on logical tree for now because visual tree is not valid during behavior OnAttachAndLoaded() zoom_control_ = graph_area_.FindLogicalParentOfType <ZoomControl>(); if (zoom_control_ == null) { // TODO throw exception! } graph_area_.VertexSelected += OnVertexSelected; graph_area_.VertexMouseUp += OnVertexMouseLeftButtonUp; graph_area_.EdgeSelected += OnEdgeSelected; zoom_control_.AreaSelected += OnVertexAreaSelected; zoom_control_.MouseLeftButtonUp += OnMouseLeftButtonUp; zoom_control_.MouseLeftButtonDown += OnMouseLeftButtonDown; selected_vertices_.CollectionChanged += OnSelectedVerticesChanged; selected_edges_.CollectionChanged += OnSelectedEdgesChanged; }
/// <summary> /// /// </summary> private void Unregister() { if (graphBehavior != null) { graphBehavior.VerticesCollectionChanged -= GraphBehavior_VerticesCollectionChanged; graphBehavior.EdgesCollectionChanged -= GraphBehavior_EdgesCollectionChanged; graphBehavior = null; } // Remove all the event handlers so this instance can be reclaimed by the GC. graph_area_.VertexSelected -= OnVertexSelected; graph_area_.VertexMouseUp -= OnVertexMouseLeftButtonUp; graph_area_.EdgeSelected -= OnEdgeSelected; zoom_control_.AreaSelected -= OnVertexAreaSelected; zoom_control_.MouseLeftButtonUp -= OnMouseLeftButtonUp; zoom_control_.MouseLeftButtonDown -= OnMouseLeftButtonDown; selected_vertices_.CollectionChanged -= OnSelectedVerticesChanged; selected_edges_.CollectionChanged -= OnSelectedEdgesChanged; zoom_control_ = null; graph_area_ = null; }
public ConnectionWrapperData(NodeGraphBehavior owner, ConnectionWrapper wrapper, NodeVertex vertex) { Owner = owner; Wrapper = wrapper; Vertex = vertex; }