/// <summary> /// 将当前元素UIElement转换成TimelinePanelChild,并赋予开始和结束时间。 /// </summary> /// <param name="uiElement">当前元素UIElement</param> /// <returns>TimelinePanelChild元素</returns> public static TimelinePanelChild ToTimelinePanelChild(this UIElement uiElement) { var startValue = uiElement.GetValue(TimelinePanel.StartDateTimeProperty); if (startValue == null) { return(null); } var start = (DateTime)startValue; var endValue = uiElement.GetValue(TimelinePanel.EndDateTimeProperty); // zorder // wrapping var returnValue = new TimelinePanelChild(uiElement) { Start = start, }; if (endValue != null) { var endValueDateTime = (DateTime)endValue; returnValue.End = (endValueDateTime == DateTime.MaxValue) ? (DateTime?)null : endValueDateTime; } return(returnValue); }
/// <summary> /// 将当前元素UIElement转换成TimelinePanelChild,并赋予开始和结束时间。 /// </summary> /// <param name="uiElement">当前元素UIElement</param> /// <returns>TimelinePanelChild元素</returns> public static TimelinePanelChild ToTimelinePanelChild(this UIElement uiElement) { var startValue = uiElement.GetValue(TimelinePanel.StartDateTimeProperty); if (startValue == null) { return null; } var start = (DateTime)startValue; var endValue = uiElement.GetValue(TimelinePanel.EndDateTimeProperty); // zorder // wrapping var returnValue = new TimelinePanelChild(uiElement) { Start = start, }; if (endValue != null) { var endValueDateTime = (DateTime)endValue; returnValue.End = (endValueDateTime == DateTime.MaxValue) ? (DateTime?)null : endValueDateTime; } return returnValue; }
private double LayoutChild(TimelinePanelChild child) { double returnValue = child.Start.ToPosition( TimelineStartDateTime, PixelsPerSecond ); if (child.Visual is FrameworkElement) { var visual = child.Visual as FrameworkElement; child.Alignment = visual.HorizontalAlignment; switch (child.Alignment) { case HorizontalAlignment.Center: returnValue -= visual.DesiredSize.Width / 2.0; break; case HorizontalAlignment.Right: returnValue -= visual.DesiredSize.Width; break; case HorizontalAlignment.Stretch: case HorizontalAlignment.Left: break; } } return(returnValue); }
/// <summary> /// 布局子元素,这是一个虚方法。 /// </summary> /// <param name="child">子元素</param> public virtual void LayoutChild(TimelinePanelChild child) { Children.Add(child); // orientation specific, childs Y is the same as the layout containers child.LayoutRect.Y = LayoutRect.Y; // expand rect to hold child _layoutRect.Union(child.LayoutRect); }
private void AddChildToLayer(TimelinePanelChild child) { if (!_layers.ContainsKey(child.ZOrder)) { // add a new layer _layers.Add(child.ZOrder, new TimelinePanelLayer(child.ZOrder)); } // add the child _layers[child.ZOrder].Children.Add(child); _sortedLayers = null; }
/// <summary> /// 添加时间线面板子元素至布局容器中 /// </summary> /// <param name="child">时间线面板子元素</param> public void AddChildToLayoutContainers(TimelinePanelChild child) { bool layedOut = false; foreach (var container in _layoutContainers) { if (container.CanLayoutChild(child)) { container.LayoutChild(child); layedOut = true; break; } // depends on orientation //nextLayoutContainer = container.LayoutRect.Y + container.LayoutRect.Height + _itemSpacerExtent; } if (!layedOut) { // depends on orientation int nextLayoutContainerOrdinal = _layoutContainers.Count; var nextLayoutContainer = (nextLayoutContainerOrdinal > 0) ? _layoutContainers.Max(container => container.LayoutRect.Bottom) : _itemSpacerExtent; _layoutContainers.Add( //new SimpleTimelineLayoutContainer( new PackingTimelineLayoutContainer( nextLayoutContainerOrdinal, 0.0, nextLayoutContainer ) ); if (_layoutContainers[nextLayoutContainerOrdinal].CanLayoutChild(child)) { _layoutContainers[nextLayoutContainerOrdinal].LayoutChild(child); } } }
/// <summary> /// 是否能够布局该子项 /// </summary> /// <param name="child">面板子元素</param> /// <returns>是否能够布局该子项</returns> public abstract bool CanLayoutChild(TimelinePanelChild child);
private double LayoutChild(TimelinePanelChild child) { double returnValue = child.Start.ToPosition( TimelineStartDateTime, PixelsPerSecond ); if (child.Visual is FrameworkElement) { var visual = child.Visual as FrameworkElement; child.Alignment = visual.HorizontalAlignment; switch (child.Alignment) { case HorizontalAlignment.Center: returnValue -= visual.DesiredSize.Width / 2.0; break; case HorizontalAlignment.Right: returnValue -= visual.DesiredSize.Width; break; case HorizontalAlignment.Stretch: case HorizontalAlignment.Left: break; } } return returnValue; }