Max vertex count of Polyline

Mar 4, 2016 at 9:22 PM
Edited Mar 4, 2016 at 9:57 PM
Hello. Im trying to achieve that my line derived from Polyline will have only 2 vertexes. I try to achievie this by overriding MaxVertexCount to 2. But this is not working properly. Its works only when i override it inside of GeneralShapes in PolylineBase. If I override it in my derived class then I can create more than one vertexes in preview but at the end It connect only first and last vertex. I want to achieve that after I draw 2 vertexes in preview it will close my drawing and insert shape like when i override it in PolylineBase. Thanks for any ideas.
Mar 6, 2016 at 8:16 PM
I change inheritance of my shape from Polyiline to PolylineBase and than ovrride MaxVertexCount after that rebuild Solution and everything is working like magic. Here is code of my custom Polyline with max 2 vertexes and EndCapStyle is ClosedArrow:
 public class ConstrainedLine : PolylineBase
    {
        internal static Shape CreateInstance(ShapeType shapeType, Template template)
        {
            Shape result = new ConstrainedLine(shapeType, template);
            return result;
        }

        /// <override></override>
        public override Shape Clone()
        {
            Shape result = new ConstrainedLine(Type, this.Template);
            result.CopyFrom(this);
            return result;
        }

        public override int MaxVertexCount
        {
            get
            {
                return 2;
            }
        }

        /// <override></override>
        protected override void InitializeToDefault(IStyleSet styleSet)
        {
            base.InitializeToDefault(styleSet);
            EndCapStyleInternal = styleSet.CapStyles.ClosedArrow;
        }

        [CategoryAppearance()]
        [Description("Defines the line cap appearance of the line's beginning.\nUse the template editor to modify all shapes of a template.\nUse the design editor to modify and create styles.")]
        [PropertyMappingId(PropertyIdStartCapStyle)]
        [RequiredPermission(Permission.Present)]
        public ICapStyle StartCapStyle
        {
            get
            {
                if (StartCapStyleInternal == null && Template == null) throw new NShapeException("Property StartCapStyle is not set.");
                return StartCapStyleInternal == null ? ((ConstrainedLine)Template.Shape).StartCapStyle : StartCapStyleInternal;
            }
            set
            {
                StartCapStyleInternal = (Template != null && value == ((ConstrainedLine)Template.Shape).StartCapStyle) ? null : value;
            }
        }


        [CategoryAppearance()]
        [Description("Defines the line cap appearance of the line's ending.\nUse the template editor to modify all shapes of a template.\nUse the design editor to modify and create styles.")]
        [PropertyMappingId(PropertyIdEndCapStyle)]
        [RequiredPermission(Permission.Present)]
        public ICapStyle EndCapStyle
        {
            get
            {
                if (EndCapStyleInternal == null && Template == null) throw new NShapeException("Property EndCapStyle is not set.");
                return EndCapStyleInternal == null ? ((ConstrainedLine)Template.Shape).EndCapStyle : EndCapStyleInternal;
            }
            set
            {
                EndCapStyleInternal = (Template != null && value == ((ConstrainedLine)Template.Shape).EndCapStyle) ? null : value;
            }
        }

        protected internal ConstrainedLine(ShapeType shapeType, Template template)
            : base(shapeType, template)
        {
        }


        protected internal ConstrainedLine(ShapeType shapeType, IStyleSet styleSet)
            : base(shapeType, styleSet)
        {
        }

        #region Fields
        private const string persistentTypeName = "MonoSegmentLine";
        #endregion
    }
Marked as answer by Sourness on 3/6/2016 at 1:17 PM