|
- using BPA.Helper;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BPASmartClient.CustomResource.UserControls
- {
- /// <summary>
- /// RankingList.xaml 的交互逻辑
- /// </summary>
- public partial class RankingList : UserControl
- {
- public RankingList()
- {
- InitializeComponent();
- this.Loaded += (s, o) =>
- {
- Refresh();
- ItemSources.ToList().ForEach(item => { item.ValueChange = new Action(() => { Refresh(); }); });
- };
- }
-
- private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as RankingList)?.Refresh();
-
- private void Refresh()
- {
- ObservableCollection<ItemPilotInfo> iCPoints = new ObservableCollection<ItemPilotInfo>();
- var max = ItemSources.Max(p => p.Value);
- ItemSources.OrderByDescending(p => p.Value).ToList().ForEach(item =>
- {
- iCPoints.Add(new ItemPilotInfo()
- {
- Name = item.Name,
- Value = item.Value,
- Width = ((double)item.Value).Scale(max + 30, 0, this.grid.ColumnDefinitions[1].ActualWidth - 30, 0),
- });
- });
- Application.Current.Dispatcher.Invoke(() =>
- {
- this.ic1.ItemsSource = iCPoints;
- this.ic2.ItemsSource = iCPoints;
- });
- }
-
-
- /// <summary>
- /// 进度条的高度
- /// </summary>
- public int LinHeight
- {
- get { return (int)GetValue(LinHeightProperty); }
- set { SetValue(LinHeightProperty, value); }
- }
- public static readonly DependencyProperty LinHeightProperty =
- DependencyProperty.Register("LinHeight", typeof(int), typeof(RankingList),
- new PropertyMetadata(10));
-
- /// <summary>
- /// 进度条的圆角度
- /// </summary>
- public CornerRadius BarCornerRadius
- {
- get { return (CornerRadius)GetValue(BarCornerRadiusProperty); }
- set { SetValue(BarCornerRadiusProperty, value); }
- }
- public static readonly DependencyProperty BarCornerRadiusProperty =
- DependencyProperty.Register("BarCornerRadius", typeof(CornerRadius), typeof(RankingList),
- new PropertyMetadata(new CornerRadius(5d)));
-
- /// <summary>
- /// 进度条之间的间隔
- /// </summary>
- public Thickness BarInterval
- {
- get { return (Thickness)GetValue(BarIntervalProperty); }
- set { SetValue(BarIntervalProperty, value); }
- }
- public static readonly DependencyProperty BarIntervalProperty =
- DependencyProperty.Register("BarInterval", typeof(Thickness), typeof(RankingList),
- new PropertyMetadata(new Thickness(5d)));
-
- /// <summary>
- /// 数值显示单位
- /// </summary>
- public string Unit
- {
- get { return (string)GetValue(UnitProperty); }
- set { SetValue(UnitProperty, value); }
- }
- public static readonly DependencyProperty UnitProperty =
- DependencyProperty.Register("Unit", typeof(string), typeof(RankingList),
- new PropertyMetadata("Unit"));
-
-
- /// <summary>
- /// 数据集合
- /// </summary>
- public ObservableCollection<BPAPilotInfo> ItemSources
- {
- get { return Application.Current.Dispatcher.Invoke(() => { return (ObservableCollection<BPAPilotInfo>)GetValue(ItemSourcesProperty); }); }
- set { SetValue(ItemSourcesProperty, value); }
- }
- public static readonly DependencyProperty ItemSourcesProperty =
- DependencyProperty.Register("ItemSources", typeof(ObservableCollection<BPAPilotInfo>), typeof(RankingList),
- new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged)));
-
-
- /// <summary>
- /// 进度条颜色
- /// </summary>
- public Brush ProgressBarColor
- {
- get { return (Brush)GetValue(ProgressBarColorProperty); }
- set { SetValue(ProgressBarColorProperty, value); }
- }
- public static readonly DependencyProperty ProgressBarColorProperty =
- DependencyProperty.Register("ProgressBarColor", typeof(Brush), typeof(RankingList),
- new PropertyMetadata(Brushes.Orange));
-
- //private void br_SizeChanged(object sender, SizeChangedEventArgs e)
- //{
- // Border border = (Border)sender;
- // if (border.Width is double.NaN) return;
- // DoubleAnimation da = new DoubleAnimation(border.Width, new Duration(TimeSpan.FromMilliseconds(500)));//指定动画的值
- // border.BeginAnimation(Border.WidthProperty, da);//指定动画对象
-
-
- // //DoubleAnimation widthAnimation = new DoubleAnimation();
- // //widthAnimation.From = 100; // 起始值
- // //widthAnimation.To = 300; // 结束值
- // //widthAnimation.Duration = new Duration(TimeSpan.FromSeconds(2)); // 动画长度
- // //Storyboard storyboard = new Storyboard();
- // //storyboard.Children.Add(widthAnimation);
- // //Storyboard.SetTarget(widthAnimation, sender as Border);
- // //Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Button.WidthProperty));
- // //storyboard.Begin();
- //}
-
-
- }
-
-
- public class BPAPilotInfo : NotifyBase
- {
- public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
- private string _mName;
-
- public float Value { get { return _mValue; } set { _mValue = value; OnPropertyChanged(); ValueChange?.Invoke(); } }
- private float _mValue;
- public Action ValueChange { get; set; }
- }
-
- public class ItemPilotInfo : BPAPilotInfo
- {
- public double Width { get { return _mWidth; } set { _mWidth = value; OnPropertyChanged(); } }
- private double _mWidth;
- }
-
-
- }
|