Example #1
0
        /// <summary>
        /// Provides the behavior for the "Arrange" pass of Silverlight layout. Classes can override this method to define their own arrange pass behavior.
        /// </summary>
        /// <param name="finalSize">The final area within the parent that this object should use to arrange itself and its children.</param>
        /// <returns>The actual size used.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            foreach (UIElement child in this.Children)
            {
                WrapPanelAttachedData data = GetWrapPanelAttachedData(child);
                child.Arrange(new Rect(data.TargetPosition.X, data.TargetPosition.Y, child.DesiredSize.Width, this.rowHeights[data.Row]));
            }

            return(finalSize);
        }
Example #2
0
        /// <summary>
        /// Gets the wrap panel attached data.
        /// </summary>
        /// <param name="obj">The <see cref="DependencyObject"/>.</param>
        /// <returns>The <see cref="WrapPanelAttachedData"/>.</returns>
        private static WrapPanelAttachedData GetWrapPanelAttachedData(DependencyObject obj)
        {
            object value = obj.GetValue(WrapPanelAttachedDataProperty);

            if (value == null)
            {
                WrapPanelAttachedData data = new WrapPanelAttachedData();
                SetAnimatedWrapPanelAttachedData(obj, data);
                return(data);
            }

            return((WrapPanelAttachedData)value);
        }
Example #3
0
        /// <summary>
        /// Provides the behavior for the "measure" pass of Silverlight layout. Classes can override this method to define their own measure pass behavior.
        /// </summary>
        /// <param name="availableSize">The available size that this object can give to child objects. Infinity can be specified as a value to indicate that the object will size to whatever content is available.</param>
        /// <returns>
        /// The size that this object determines it needs during layout, based on its calculations of child object allotted sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            foreach (FrameworkElement child in this.Children)
            {
                child.Measure(availableSize);
            }

            double rowHeight = 0;
            int    row       = 0;

            this.rowHeights.Clear();
            this.indexRowMapping.Clear();
            Size  desiredSize       = Size.Empty;
            int   elementNo         = 0;
            Point nextChildPosition = new Point(0, 0);

            foreach (FrameworkElement child in this.Children)
            {
                if (nextChildPosition.X + child.DesiredSize.Width > availableSize.Width)
                {
                    this.rowHeights.Add(rowHeight);
                    ++row;
                    nextChildPosition.X  = 0;
                    nextChildPosition.Y += rowHeight;
                    rowHeight            = 0;
                }

                // Insert the index of the item and the row no.
                this.indexRowMapping.Add(elementNo, row);
                elementNo++;

                WrapPanelAttachedData data = GetWrapPanelAttachedData(child);

                if (data.TargetPosition != nextChildPosition)
                {
                    data.TargetPosition = nextChildPosition;
                    data.Row            = row;
                }

                desiredSize.Width  = Math.Max(desiredSize.Width, nextChildPosition.X + child.DesiredSize.Width);
                desiredSize.Height = Math.Max(desiredSize.Height, nextChildPosition.Y + child.DesiredSize.Height);

                rowHeight = Math.Max(rowHeight, child.DesiredSize.Height);

                nextChildPosition.X += child.DesiredSize.Width;
            }

            this.rowHeights.Add(rowHeight);

            return(desiredSize);
        }
Example #4
0
 /// <summary>
 /// Sets the <see cref="WrapPanelAttachedData"/>.
 /// </summary>
 /// <param name="obj">The <see cref="DependencyObject"/>.</param>
 /// <param name="value">The <see cref="WrapPanelAttachedData"/>.</param>
 private static void SetAnimatedWrapPanelAttachedData(DependencyObject obj, WrapPanelAttachedData value)
 {
     obj.SetValue(WrapPanelAttachedDataProperty, value);
 }