Example #1
0
        /// <summary>
        /// The create shape method.
        /// </summary>
        /// <param name="type">
        /// The type of shape to create.
        /// </param>
        /// <returns>
        /// The <see cref="ShapeInstance"/> created.
        /// </returns>
        public static ShapeInstance CreateShape(ShapeType type)
        {
            var shape = new ShapeInstance
            {
                Type        = type,
                Description = Enum.GetName(typeof(ShapeType), type)
            };

            return(shape);
        }
Example #2
0
        /// <summary>
        /// The create shape.
        /// </summary>
        /// <param name="shape">
        /// The shape.
        /// </param>
        /// <returns>
        /// The <see cref="FrameworkElement"/> instance of the shape.
        /// </returns>
        private FrameworkElement CreateShape(ShapeInstance shape)
        {
            FrameworkElement uiElement;

            if (shape == null)
            {
                uiElement = new Grid();
                return(uiElement);
            }

            if (shape.Type.Equals(ShapeType.Circle) ||
                shape.Type.Equals(ShapeType.Ellipse))
            {
                uiElement = new Ellipse();
            }
            else
            {
                uiElement = new Rectangle();
            }

            uiElement.SetValue(FrameworkElement.HeightProperty, 100.0);

            double width;

            if (shape.Type.Equals(ShapeType.Circle) || shape.Type.Equals(ShapeType.Square))
            {
                width = 100.0;
            }
            else
            {
                width = 200.0;
                uiElement.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 2.0);
            }

            uiElement.SetValue(FrameworkElement.WidthProperty, width);
            uiElement.SetValue(Shape.StrokeThicknessProperty, 5.0);
            uiElement.SetValue(
                Shape.StrokeProperty,
                new SolidColorBrush(Palette[Random.Next(Palette.Length)]));
            uiElement.SetValue(
                Shape.FillProperty,
                new SolidColorBrush(Palette[Random.Next(Palette.Length)]));

            return(uiElement);
        }
Example #3
0
        /// <summary>
        /// The generate shape method.
        /// </summary>
        /// <returns>
        /// The <see cref="ShapeInstance"/> generated.
        /// </returns>
        public static ShapeInstance GenerateShape()
        {
            var type = Types[Random.Next(Types.Length)];

            return(ShapeInstance.CreateShape(type));
        }