public DashStyleComboBox(DashStyleEx selected) : this() { SetDataSource(selected); }
void SetDataSource(DashStyleEx selected) { if (_dashStyles == null) SetDefaultValues(); if (!_dashStyles.Contains(selected)) _dashStyles.Add(selected.Clone()); this.BeginUpdate(); Items.Clear(); foreach (DashStyleEx o in _dashStyles) Items.Add(o); SelectedItem = selected; this.EndUpdate(); }
public void CopyFrom(DashStyleEx from) { if (object.ReferenceEquals(this, from)) return; this._knownStyle = from.KnownStyle; this._customStyle = from._customStyle == null ? null : (float[])from._customStyle.Clone(); }
public DashStyleEx(DashStyleEx from) { CopyFrom(from); }
public static ImageSource GetImage(DashStyleEx val) { const double height = 1; const double width = 2; const double lineWidth = height / 5; DashStyle dashStyle = DashStyles.Solid; if (val.IsKnownStyle) { if (val == DashStyleEx.Solid) dashStyle = DashStyles.Solid; else if (val == DashStyleEx.Dash) dashStyle = DashStyles.Dash; else if (val == DashStyleEx.Dot) dashStyle = DashStyles.Dot; else if (val == DashStyleEx.DashDot) dashStyle = DashStyles.DashDot; else if (val == DashStyleEx.DashDotDot) dashStyle = DashStyles.DashDotDot; else if (val == DashStyleEx.LongDash) dashStyle = new DashStyle(new double[] { 5, 2 }, 0); } else if (val.IsCustomStyle) { var list = new List<double>(); foreach (var e in val.CustomStyle) list.Add(e); dashStyle = new DashStyle(list, 0); } // draws a transparent outline to fix the borders var drawingGroup = new DrawingGroup(); var geometryDrawing = new GeometryDrawing(); geometryDrawing.Geometry = new RectangleGeometry(new Rect(0, 0, width, height)); geometryDrawing.Pen = new Pen(Brushes.Transparent, 0); drawingGroup.Children.Add(geometryDrawing); geometryDrawing = new GeometryDrawing() { Geometry = new LineGeometry(new Point(0, height / 2), new Point(width, height / 2)) }; geometryDrawing.Pen = new Pen(Brushes.Black, lineWidth) { DashStyle = dashStyle }; drawingGroup.Children.Add(geometryDrawing); var geometryImage = new DrawingImage(drawingGroup); // Freeze the DrawingImage for performance benefits. geometryImage.Freeze(); return geometryImage; }
public void CopyFrom(DashStyleEx from) { this._knownStyle = from.KnownStyle; this._customStyle = from._customStyle == null ? null : (float[])from._customStyle.Clone(); }