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 TeamAAS_VP.Controls
{
///
/// myNumericUpDowm.xaml 的交互逻辑
///
public partial class myNumericUpDowm : UserControl, INotifyPropertyChanged
{
//
// 摘要:
// Identifies the MahApps.Metro.Controls.NumericUpDown.ValueChanged routed event.
public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent(
"ValueChanged",
RoutingStrategy.Bubble,
typeof(RoutedEventHandler),
typeof(myNumericUpDowm));
//
// 摘要:
// Add / Remove ValueChangedEvent handler Event which will be fired from this NumericUpDown
// when its value has been changed.
public event RoutedEventHandler ValueChanged
{
add
{
AddHandler(ValueChangedEvent, value);
}
remove
{
RemoveHandler(ValueChangedEvent, value);
}
}
public myNumericUpDowm()
{
InitializeComponent();
this.MotorAmplitudeNumeric1.ValueChanged += MotorAmplitudeNumeric1_ValueChanged;
}
private void MotorAmplitudeNumeric1_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
Value = e.NewValue;
}
[Bindable(true)]
[Category("Common")]
[DefaultValue(null)]
public double? Value
{
get { return (double?)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); NotifyValueChanged(value); }
}
// Using a DependencyProperty as the backing store for Value. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double?), typeof(myNumericUpDowm), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(PropertyValueChanged)));
[Bindable(true)]
[Category("Common")]
[DefaultValue("")]
public string StringFormat
{
get { return (string)GetValue(StringFormatProperty); }
set { SetValue(StringFormatProperty, value); }
}
// Using a DependencyProperty as the backing store for StringFormat. This enables animation, styling, binding, etc...
public static readonly DependencyProperty StringFormatProperty =
DependencyProperty.Register("StringFormat", typeof(string), typeof(myNumericUpDowm), new PropertyMetadata("", new PropertyChangedCallback(PropertyValueChanged)));
[Bindable(true)]
[Category("Common")]
[DefaultValue(double.MinValue)]
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
// Using a DependencyProperty as the backing store for Minimum. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(double), typeof(myNumericUpDowm), new PropertyMetadata(double.MinValue, new PropertyChangedCallback(PropertyValueChanged)));
[Bindable(true)]
[Category("Common")]
[DefaultValue(double.MaxValue)]
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
// Using a DependencyProperty as the backing store for Maximum. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(double), typeof(myNumericUpDowm), new PropertyMetadata(double.MaxValue, new PropertyChangedCallback(PropertyValueChanged)));
[Bindable(true)]
[Category("Common")]
[DefaultValue(1.0)]
public double Interval
{
get { return (double)GetValue(IntervalProperty); }
set { SetValue(IntervalProperty, value); }
}
// Using a DependencyProperty as the backing store for Interval. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IntervalProperty =
DependencyProperty.Register("Interval", typeof(double), typeof(myNumericUpDowm), new PropertyMetadata(1.0, new PropertyChangedCallback(PropertyValueChanged)));
public event PropertyChangedEventHandler PropertyChanged;
private static void PropertyValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as myNumericUpDowm).Update();
}
private void Update()
{
this.MotorAmplitudeNumeric1.Value = Value;
this.MotorAmplitudeNumeric1.StringFormat = StringFormat;
this.MotorAmplitudeNumeric1.Minimum = Minimum;
this.MotorAmplitudeNumeric1.Maximum = Maximum;
this.MotorAmplitudeNumeric1.Interval = Interval;
this.slider2.SmallChange = Interval;
this.slider2.TickFrequency= Interval;
}
// 触发 ValueChanged 事件的方法
protected virtual void OnValueChanged(double? newValue)
{
RoutedEventArgs args = new RoutedEventArgs(ValueChangedEvent, newValue);
RaiseEvent(args);
}
// 用户控件的值发生变化时调用此方法
private void NotifyValueChanged(double? newValue)
{
OnValueChanged(newValue);
}
}
}