I am trying to create a WPF application that will have a custom rectangle shape. Since Rectangle is a sealed class I have to inherit from Shape class. Basically my rectangle will consist of four corners (triangles) and 4 edges (trapezoids) that the user can interact with by selecting and dragging the edge or corner to resize the rectangle. Each side/corner will highlight when the mouse is over it (opacity on or off). The body can also be clicked on to move the rectangle. I envision having 8 different RenderedGeometry functions for the 4 corners and 4 sides.
However, my question is mainly about how I begin my definition of a custom Shape object? This is what I can think of for a start based on the Rectangle class:
Expand|Select|Wrap|Line Numbers
- public sealed class dsgnShape : Shape
- {
- public dsgnShape();
- protected override Geometry DefiningGeometry { get; }
- public override Transform GeometryTransform { get; }
- public override Geometry RenderedGeometry { get; }
- protected override Size ArrangeOverride(Size finalSize);
- protected override Size MeasureOverride(Size constraint);
- protected override void OnRender(DrawingContext drawingContext);
- }
For quick reference here is the Shape class:
Expand|Select|Wrap|Line Numbers
- public abstract class Shape : FrameworkElement
- {
- public static readonly DependencyProperty FillProperty;
- public static readonly DependencyProperty StretchProperty;
- public static readonly DependencyProperty StrokeDashArrayProperty;
- public static readonly DependencyProperty StrokeDashCapProperty;
- public static readonly DependencyProperty StrokeDashOffsetProperty;
- public static readonly DependencyProperty StrokeEndLineCapProperty;
- public static readonly DependencyProperty StrokeLineJoinProperty;
- public static readonly DependencyProperty StrokeMiterLimitProperty;
- public static readonly DependencyProperty StrokeProperty;
- public static readonly DependencyProperty StrokeStartLineCapProperty;
- public static readonly DependencyProperty StrokeThicknessProperty;
- protected Shape();
- protected abstract Geometry DefiningGeometry { get; }
- public Brush Fill { get; set; }
- public virtual Transform GeometryTransform { get; }
- public virtual Geometry RenderedGeometry { get; }
- public Stretch Stretch { get; set; }
- public Brush Stroke { get; set; }
- public DoubleCollection StrokeDashArray { get; set; }
- public PenLineCap StrokeDashCap { get; set; }
- public double StrokeDashOffset { get; set; }
- public PenLineCap StrokeEndLineCap { get; set; }
- public PenLineJoin StrokeLineJoin { get; set; }
- public double StrokeMiterLimit { get; set; }
- public PenLineCap StrokeStartLineCap { get; set; }
- [TypeConverter(typeof(LengthConverter))]
- public double StrokeThickness { get; set; }
- protected override Size ArrangeOverride(Size finalSize);
- protected override Size MeasureOverride(Size constraint);
- protected override void OnRender(DrawingContext drawingContext);
- }