123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows;
- namespace PDF_Master.CustomControl
- {
- public class StepBarItem : ContentControl
- {
- #region 依赖属性定义
- public string Number
- {
- get { return (string)GetValue(NumberProperty); }
- set { SetValue(NumberProperty, value); }
- }
- public static readonly DependencyProperty NumberProperty =
- DependencyProperty.Register("Number", typeof(string), typeof(StepBarItem));
- #endregion 依赖属性定义
- #region Constructors
- static StepBarItem()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(StepBarItem), new FrameworkPropertyMetadata(typeof(StepBarItem)));
- }
- #endregion Constructors
- }
- public class StepBar : ItemsControl
- {
- #region Progress
- public int CurrentIndex
- {
- get { return (int)GetValue(CurrentIndexProperty); }
- set { SetValue(CurrentIndexProperty, value); }
- }
- public static readonly DependencyProperty CurrentIndexProperty =
- DependencyProperty.Register("CurrentIndex", typeof(int), typeof(StepBar), new PropertyMetadata(0));
- public Brush ActivateColor
- {
- get { return (Brush)GetValue(ActivateColorProperty); }
- set { SetValue(ActivateColorProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ActivateColor. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ActivateColorProperty =
- DependencyProperty.Register("ActivateColor", typeof(Brush), typeof(StepBar), new PropertyMetadata(new SolidColorBrush(Colors.Green)));
- public Brush UnActivateColor
- {
- get { return (Brush)GetValue(UnActivateColorProperty); }
- set { SetValue(UnActivateColorProperty, value); }
- }
- // Using a DependencyProperty as the backing store for UnActivateColor. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty UnActivateColorProperty =
- DependencyProperty.Register("UnActivateColor", typeof(Brush), typeof(StepBar), new PropertyMetadata(new SolidColorBrush(Colors.Gray)));
- /// <summary>
- /// 线的最小长度
- /// </summary>
- public double LineMinLength
- {
- get { return (double)GetValue(LineMinLengthProperty); }
- set { SetValue(LineMinLengthProperty, value); }
- }
- // Using a DependencyProperty as the backing store for LineMinLength. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty LineMinLengthProperty =
- DependencyProperty.Register("LineMinLength", typeof(double), typeof(StepBar), new PropertyMetadata(50d));
- public Orientation Orientation
- {
- get { return (Orientation)GetValue(OrientationProperty); }
- set { SetValue(OrientationProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Orientation. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty OrientationProperty =
- DependencyProperty.Register("Orientation", typeof(Orientation), typeof(StepBar), new PropertyMetadata(Orientation.Horizontal));
- #endregion Progress
- #region Constructors
- static StepBar()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(StepBar), new FrameworkPropertyMetadata(typeof(StepBar)));
- }
- #endregion Constructors
- #region Override方法
- protected override DependencyObject GetContainerForItemOverride()
- {
- return new StepBarItem();
- }
- 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);
- }
- 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;
- }
- #endregion Override方法
- }
- }
|