/// <summary> /// Animate the new person that was added to the diagram. /// </summary> private void AnimateNewPerson() { // The new person is optional, can be null. if (newPerson == null) { return; } // Get the UI element to animate. DiagramNode node = logic.GetDiagramNode(newPerson); if (node != null) { // Create the new person animation. DoubleAnimation anim = new DoubleAnimation(0, 1, GlobalData.GetAnimationDuration(Const.NewPersonAnimationDuration)); // Animate the node. ScaleTransform transform = new ScaleTransform(); transform.BeginAnimation(ScaleTransform.ScaleXProperty, anim); transform.BeginAnimation(ScaleTransform.ScaleYProperty, anim); node.RenderTransform = transform; } newPerson = null; }
/// <summary> /// Called when data changed in the main People collection. This can be /// a new node added to the collection, updated Person details, and /// updated relationship data. /// </summary> private void OnFamilyContentChanged(object sender, ContentChangedEventArgs e) { // Ignore if currently repopulating the diagram. if (populating) { return; } // Save the person that is being added to the diagram. // This is optional and can be null. newPerson = e.NewShape; // Redraw the diagram. UpdateDiagram(); this.InvalidateMeasure(); this.InvalidateArrange(); this.InvalidateVisual(); }
/// <summary> /// Reset the diagram with the nodes. This is accomplished by creating a series of rows. /// Each row contains a series of groups, and each group contains the nodes. The elements /// are not laid out at this time. Also creates the connections between the nodes. /// </summary> private void UpdateDiagram() { // Necessary for Blend. if (logic.Family == null) { return; } // First reset everything. Clear(); // Nothing to draw if there is not a primary person. if (logic.Family.Current == null) { return; } // Primary row. DrawStructure.Main.Shape primaryPerson = logic.Family.Current; DiagramRow primaryRow = logic.CreatePrimaryRow(primaryPerson, 1.0, Const.RelatedMultiplier); primaryRow.GroupSpace = Const.PrimaryRowGroupSpace; AddRow(primaryRow); // Create as many rows as possible until exceed the max node limit. // Switch between child and parent rows to prevent only creating // child or parents rows (want to create as many of each as possible). int nodeCount = this.NodeCount; // The scale values of future generations, this makes the nodes // in each row slightly smaller. double nodeScale = 1.0; DiagramRow childRow = primaryRow; DiagramRow parentRow = primaryRow; while (nodeCount < Const.MaximumNodes && (childRow != null || parentRow != null)) { // Child Row. if (childRow != null) { childRow = AddChildRow(childRow); } // Parent row. if (parentRow != null) { nodeScale *= Const.GenerationMultiplier; parentRow = AddParentRow(parentRow, nodeScale); } // See if reached node limit yet. nodeCount = this.NodeCount; } // Raise event so others know the diagram was updated. OnDiagramUpdated(); // Animate the new person (optional, might not be any new people). AnimateNewPerson(); }