protected override Size ArrangeOverride(Size finalSize) { m_listener.StartListening(); // Calculate how many children fit on each row int childrenPerRow = Math.Max(1, (int)Math.Floor(finalSize.Width / this.ItemWidth)); bool animateNewItem = AnimatesNewItem && m_hasArranged; m_hasArranged = true; Size theChildSize = new Size(this.ItemWidth, this.ItemHeight); for (int i = 0; i < this.Children.Count; i++) { UIElement child = this.Children[i]; // Figure out where the child goes Point newOffset = calculateChildOffset(i, childrenPerRow, this.ItemWidth, this.ItemHeight, finalSize.Width, this.Children.Count); AnimatingTilePanelData data = (AnimatingTilePanelData)child.GetValue(DataProperty); if (data == null) { data = new AnimatingTilePanelData(); child.SetValue(DataProperty, data); } //set the location attached DP data.ChildTarget = newOffset; if (data.IsNew) // first time I've seen this... { data.IsNew = false; if (animateNewItem) { newOffset.X -= theChildSize.Width; } data.ChildLocation = newOffset; child.Arrange(new Rect(newOffset, theChildSize)); } else { Point currentOffset = data.ChildLocation; // Position the child and set its size child.Arrange(new Rect(currentOffset, theChildSize)); } } return(finalSize); }
private static bool updateElement(AnimatingTilePanelData data, double dampening, double attractionFactor, double variation) { Debug.Assert(dampening > 0 && dampening < 1); Debug.Assert(attractionFactor > 0 && !double.IsInfinity(attractionFactor)); attractionFactor *= 1 + (variation * data.Random - .5); Point newLocation; Vector newVelocity; bool anythingChanged = WpfUtil.Animate(data.ChildLocation, data.Velocity, data.ChildTarget, attractionFactor, dampening, c_terminalVelocity, c_diff, c_diff, out newLocation, out newVelocity); data.ChildLocation = newLocation; data.Velocity = newVelocity; return(anythingChanged); }
private static bool updateElement(AnimatingTilePanelData data, double dampening, double attractionFactor, double variation) { Debug.Assert(dampening > 0 && dampening < 1); Debug.Assert(attractionFactor > 0 && !double.IsInfinity(attractionFactor)); attractionFactor *= 1 + (variation * data.Random - .5); Point newLocation; Vector newVelocity; bool anythingChanged = WpfUtil.Animate(data.ChildLocation, data.Velocity, data.ChildTarget, attractionFactor, dampening, c_terminalVelocity, c_diff, c_diff, out newLocation, out newVelocity); data.ChildLocation = newLocation; data.Velocity = newVelocity; return anythingChanged; }
protected override Size ArrangeOverride(Size finalSize) { m_listener.StartListening(); // Calculate how many children fit on each row int childrenPerRow = Math.Max(1, (int)Math.Floor(finalSize.Width / this.ItemWidth)); bool animateNewItem = AnimatesNewItem && m_hasArranged; m_hasArranged = true; Size theChildSize = new Size(this.ItemWidth, this.ItemHeight); for (int i = 0; i < this.Children.Count; i++) { UIElement child = this.Children[i]; // Figure out where the child goes Point newOffset = calculateChildOffset(i, childrenPerRow, this.ItemWidth, this.ItemHeight, finalSize.Width, this.Children.Count); AnimatingTilePanelData data = (AnimatingTilePanelData)child.GetValue(DataProperty); if (data == null) { data = new AnimatingTilePanelData(); child.SetValue(DataProperty, data); } //set the location attached DP data.ChildTarget = newOffset; if (data.IsNew) // first time I've seen this... { data.IsNew = false; if (animateNewItem) { newOffset.X -= theChildSize.Width; } data.ChildLocation = newOffset; child.Arrange(new Rect(newOffset, theChildSize)); } else { Point currentOffset = data.ChildLocation; // Position the child and set its size child.Arrange(new Rect(currentOffset, theChildSize)); } } return finalSize; }