Beispiel #1
0
 protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
 {
     //设置Item的显示数字
     StepBarItem stepBarItem = element as StepBarItem;
     ItemsControl itemsControl = ItemsControl.ItemsControlFromItemContainer(stepBarItem);
     int index = itemsControl.ItemContainerGenerator.IndexFromContainer(stepBarItem);
     stepBarItem.Number = Convert.ToString(++index);
     base.PrepareContainerForItemOverride(element, item);
 }
Beispiel #2
0
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            //ItemsControl数量变化时,重新设置各个Item的显示的数字
            for (int i = 0; i < this.Items.Count; i++)
            {
                StepBarItem stepBarItem = this.ItemContainerGenerator.ContainerFromIndex(i) as StepBarItem;
                if(stepBarItem != null)
                {
                    int temp = i;
                    stepBarItem.Number = Convert.ToString(++temp);
                }
            }
            //进度重新回到第一个
            this.Progress = 0;
        }