/// <summary> /// Create hour range visual element - label with hairlines /// </summary> private DrawingVisual _CreateVisualItem(DateTime dateTime, int durationInHour, Rect bound) { GanttTimeLineItem item = new GanttTimeLineItem(durationInHour); int hairLineCount = (1 == durationInHour) ? _style.PartPerHour : durationInHour; RenderOptions.SetEdgeMode((DependencyObject)item, EdgeMode.Aliased); using (DrawingContext dc = item.RenderOpen()) { // Draw hairlines. double offset = bound.Width / hairLineCount; // Start offset. Point bottomLeft = bound.BottomLeft; Point pt1 = bottomLeft; Point pt2 = bottomLeft; // Draw hairline. for (int index = 0; index <= hairLineCount; ++index) { // Start and end hairlines with full height other with selected. pt2.Y = ((0 == index) || (hairLineCount == index)) ? 0 : bound.Height - _style.HairlineHeight; // draw vertical line double x = Math.Floor(pt1.X); dc.DrawLine(_style.HairlinePen, new Point(x, pt1.Y), new Point(x, pt2.Y)); pt1.X += offset; } // Draw lable. CultureInfo cultureInfo = CultureInfo.CurrentCulture; FormattedText formattedText = new FormattedText(_GetTimeString(dateTime, cultureInfo), cultureInfo, FlowDirection.LeftToRight, _style.FontTypeface, _style.FontSize, _style.FontBrush); Point textPosition = new Point(bottomLeft.X + _style.LabelMargin.Width, _style.LabelMargin.Height); dc.DrawText(formattedText, textPosition); } // Add clip rect for visual element. RectangleGeometry clipGeometry = new RectangleGeometry(); clipGeometry.Rect = bound; item.Clip = clipGeometry; return(item); }
/// <summary> /// Create hour range visual element - label with hairlines /// </summary> private DrawingVisual _CreateVisualItem(DateTime dateTime, int durationInHour, Rect bound) { GanttTimeLineItem item = new GanttTimeLineItem(durationInHour); int hairLineCount = (1 == durationInHour) ? _style.PartPerHour : durationInHour; RenderOptions.SetEdgeMode((DependencyObject)item, EdgeMode.Aliased); using (DrawingContext dc = item.RenderOpen()) { // Draw hairlines. double offset = bound.Width / hairLineCount; // Start offset. Point bottomLeft = bound.BottomLeft; Point pt1 = bottomLeft; Point pt2 = bottomLeft; // Draw hairline. for (int index = 0; index <= hairLineCount; ++index) { // Start and end hairlines with full height other with selected. pt2.Y = ((0 == index) || (hairLineCount == index)) ? 0 : bound.Height - _style.HairlineHeight; // draw vertical line double x = Math.Floor(pt1.X); dc.DrawLine(_style.HairlinePen, new Point(x, pt1.Y), new Point(x, pt2.Y)); pt1.X += offset; } // Draw lable. CultureInfo cultureInfo = CultureInfo.CurrentCulture; FormattedText formattedText = new FormattedText(_GetTimeString(dateTime, cultureInfo), cultureInfo, FlowDirection.LeftToRight, _style.FontTypeface, _style.FontSize, _style.FontBrush); Point textPosition = new Point(bottomLeft.X + _style.LabelMargin.Width, _style.LabelMargin.Height); dc.DrawText(formattedText, textPosition); } // Add clip rect for visual element. RectangleGeometry clipGeometry = new RectangleGeometry(); clipGeometry.Rect = bound; item.Clip = clipGeometry; return item; }