Beispiel #1
0
        private static void OnMinimumHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RandomPanel panel = ( RandomPanel )d;

            panel.CoerceValue(RandomPanel.MaximumHeightProperty);
            panel.InvalidateMeasure();
        }
Beispiel #2
0
 private static void SeedChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
 {
     if (obj is RandomPanel)
     {
         RandomPanel owner = ( RandomPanel )obj;
         owner._random = new Random(( int )args.NewValue);
         owner.InvalidateArrange();
     }
 }
Beispiel #3
0
        private static object CoerceMinimumWidth(DependencyObject d, object baseValue)
        {
            RandomPanel panel = ( RandomPanel )d;
            double      value = ( double )baseValue;

            if (double.IsNaN(value) || double.IsInfinity(value) || (value < 0d))
            {
                return(DependencyProperty.UnsetValue);
            }

            double maximum = panel.MaximumWidth;

            if (value > maximum)
            {
                return(maximum);
            }

            return(baseValue);
        }
Beispiel #4
0
        protected override Size MeasureChildrenOverride(UIElementCollection children, Size constraint)
        {
            Size availableSize = new Size(double.PositiveInfinity, double.PositiveInfinity);

            foreach (UIElement child in children)
            {
                if (child == null)
                {
                    continue;
                }

                Size childSize = new Size(1d * _random.Next(Convert.ToInt32(MinimumWidth), Convert.ToInt32(MaximumWidth)),
                                          1d * _random.Next(Convert.ToInt32(MinimumHeight), Convert.ToInt32(MaximumHeight)));

                child.Measure(childSize);
                RandomPanel.SetActualSize(child, childSize);
            }
            return(new Size());
        }
Beispiel #5
0
        protected override Size ArrangeChildrenOverride(UIElementCollection children, Size finalSize)
        {
            foreach (UIElement child in children)
            {
                if (child == null)
                {
                    continue;
                }

                Size childSize = RandomPanel.GetActualSize(child);

                double x = _random.Next(0, ( int )(Math.Max(finalSize.Width - childSize.Width, 0)));
                double y = _random.Next(0, ( int )(Math.Max(finalSize.Height - childSize.Height, 0)));

                double width  = Math.Min(finalSize.Width, childSize.Width);
                double height = Math.Min(finalSize.Height, childSize.Height);

                this.ArrangeChild(child, new Rect(new Point(x, y), new Size(width, height)));
            }
            return(finalSize);
        }