/// <summary> /// 设置TimelineItem的位置属性 /// </summary> /// <param name="index"></param> private void SetTimelineItem(int index) { if (index > this.Items.Count || index < 0) { return; } TimelineItem timelineItem = this.ItemContainerGenerator.ContainerFromIndex(index) as TimelineItem; if (timelineItem == null) { return; } timelineItem.IsFirstItem = index == 0; timelineItem.IsLastItem = index == this.Items.Count - 1; timelineItem.IsMiddleItem = index > 0 && index < this.Items.Count - 1; }
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) { int index = this.ItemContainerGenerator.IndexFromContainer(element); TimelineItem timelineItem = element as TimelineItem; if (timelineItem == null) { return; } if (index == 0) { timelineItem.IsFirstItem = true; } if (index == this.Items.Count - 1) { timelineItem.IsLastItem = true; } base.PrepareContainerForItemOverride(timelineItem, item); }