using LiveCharts;
using LiveCharts.Configurations;
using LiveCharts.Defaults;
using LiveCharts.Helpers;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.ComponentModel;
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 Chen.Controls
{
///
/// Parameter.xaml 的交互逻辑
///
public partial class Parameter : UserControl
{
//依赖属性,依赖对象
//包装器
public string Value
{
get { return (string)this.GetValue(ValueProperty); }
set { this.SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(Parameter), new PropertyMetadata(default(string), new PropertyChangedCallback(OnPropertyChanged)));
//图标
public string Tb_Page
{
get { return (string)GetValue(Tb_PageProperty); }
set { SetValue(Tb_PageProperty, value); }
}
// Using a DependencyProperty as the backing store for Tb_Page. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Tb_PageProperty =
DependencyProperty.Register("Tb_Page", typeof(string), typeof(Parameter), new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged)));
//主题色
public Brush Theme_Color
{
get { return (Brush)GetValue(Theme_ColorProperty); }
set { SetValue(Theme_ColorProperty, value); }
}
// Using a DependencyProperty as the backing store for _color. This enables animation, styling, binding, etc...
public static readonly DependencyProperty Theme_ColorProperty =
DependencyProperty.Register("Theme_Color", typeof(Brush), typeof(Parameter), new PropertyMetadata(default(Brush), new PropertyChangedCallback(OnPropertyChanged)));
//文本标题
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
// Using a DependencyProperty as the backing store for Title. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register("Title", typeof(string), typeof(Parameter), new PropertyMetadata(default(string), new PropertyChangedCallback(OnPropertyChanged)));
//最小值
public int Minimum
{
get { return (int)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(int), typeof(Parameter), new PropertyMetadata(default(int), new PropertyChangedCallback(OnPropertyChanged)));
//最大值
public int Maximum
{
get { return (int)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(int), typeof(Parameter),
new PropertyMetadata(default(int), new PropertyChangedCallback(OnPropertyChanged)));
//数组值
public ChartValues Values
{
get { return (ChartValues)GetValue(ValuesProperty); }
set { SetValue(ValuesProperty, value); }
}
// Using a DependencyProperty as the backing store for Values. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ValuesProperty =
DependencyProperty.Register("Values", typeof(ChartValues), typeof(Parameter), new PropertyMetadata(default(ChartValues), new PropertyChangedCallback(OnPropertyChanged)));
public List datetime
{
get { return (List)GetValue(datetimeProperty); }
set { SetValue(datetimeProperty, value); }
}
// Using a DependencyProperty as the backing store for Values. This enables animation, styling, binding, etc...
public static readonly DependencyProperty datetimeProperty =
DependencyProperty.Register("datetime", typeof(List), typeof(Parameter), new PropertyMetadata(default(List), new PropertyChangedCallback(OnPropertyChanged)));
public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as Parameter).Refresh();
}
public Parameter()
{
InitializeComponent();
}
public Func DateTimeFormatter { get; set; }
private void Refresh()
{
//将换成\u 如 变成\ue601
this.TB.Text = this.Tb_Page;
this.TB.Foreground = this.Theme_Color;
this.Cs_Name1.Text = this.Title;
this.Cs_Name2.Text = this.Title;
this.Cs_Name2.Foreground = this.Theme_Color;
this.TB2.Foreground = this.Theme_Color;
this._value.Text = this.Value;
this.Chart.Series.Clear();
this.Chart.AxisX.Clear();
this.Chart.AxisY.Clear();
//if (Values.Count == 0)
//{
// Values = new List { 1};
//}
//折线图
this.Chart.Series.Add(new LineSeries
{
Title = this.Title,
Values = Values,
Stroke = this.Theme_Color,
Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255)),
PointGeometrySize = 0
});
this.Chart.AxisX.Add(new Axis
{
LabelsRotation = 150,
ShowLabels = true,
Labels = datetime
});
this.Chart.AxisY.Add(new Axis
{
ShowLabels = true,
MinValue = this.Minimum,
MaxValue = this.Maximum
}) ;
}
}
}