141 lines
4.7 KiB
C#
141 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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.Markup;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace VisionCommonUI {
|
|
/// <summary>
|
|
/// Interaction logic for UCContentSlider.xaml
|
|
/// </summary>
|
|
public class SliderChangedEventArgs : EventArgs {
|
|
public double NewValue { get; set; }
|
|
|
|
public SliderChangedEventArgs(double newValue) {
|
|
NewValue = newValue;
|
|
}
|
|
}
|
|
|
|
[ContentProperty("InnerContent")]
|
|
public partial class UCContentSlider : UserControl {
|
|
public event EventHandler SliderChangedEvent;
|
|
public static Type _classType = typeof(UCContentSlider);
|
|
|
|
public static readonly DependencyProperty InnerContentProperty
|
|
= DependencyProperty.Register(
|
|
nameof(InnerContent),
|
|
typeof(FrameworkElement),
|
|
_classType);
|
|
|
|
public FrameworkElement InnerContent {
|
|
get { return (FrameworkElement)GetValue(InnerContentProperty); }
|
|
set { SetValue(InnerContentProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty KeyValueProperty
|
|
= DependencyProperty.Register(
|
|
nameof(KeyValue),
|
|
typeof(double),
|
|
_classType,
|
|
new FrameworkPropertyMetadata(
|
|
0.0,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
|
|
(d, e) => (d as UCContentSlider).OnKeyValueChanged(e)
|
|
));
|
|
|
|
private void OnKeyValueChanged(DependencyPropertyChangedEventArgs e) {
|
|
SliderChangedEvent?.Invoke(this, new SliderChangedEventArgs(Convert.ToDouble(e.NewValue)));
|
|
}
|
|
|
|
public double KeyValue {
|
|
get { return (double)GetValue(KeyValueProperty); }
|
|
set { SetValue(KeyValueProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty MinValueProperty
|
|
= DependencyProperty.Register(
|
|
nameof(MinValue),
|
|
typeof(double),
|
|
_classType);
|
|
|
|
public double MinValue {
|
|
get { return (double)GetValue(MinValueProperty); }
|
|
set { SetValue(MinValueProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty MaxValueProperty
|
|
= DependencyProperty.Register(
|
|
nameof(MaxValue),
|
|
typeof(double),
|
|
_classType);
|
|
|
|
public double MaxValue {
|
|
get { return (double)GetValue(MaxValueProperty); }
|
|
set { SetValue(MaxValueProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty TickFrequencyProperty
|
|
= DependencyProperty.Register(
|
|
nameof(TickFrequency),
|
|
typeof(double),
|
|
_classType,
|
|
new FrameworkPropertyMetadata(
|
|
10.0,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public double TickFrequency {
|
|
get { return (double)GetValue(TickFrequencyProperty); }
|
|
set { SetValue(TickFrequencyProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty StepProperty
|
|
= DependencyProperty.Register(
|
|
nameof(Step),
|
|
typeof(double),
|
|
_classType,
|
|
new FrameworkPropertyMetadata(
|
|
1.0,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public double Step {
|
|
get { return (double)GetValue(StepProperty); }
|
|
set { SetValue(StepProperty, value); }
|
|
}
|
|
|
|
public UCContentSlider() {
|
|
InitializeComponent();
|
|
DataContext = this;
|
|
}
|
|
|
|
private void OnMinusBtnClicked(object sender, RoutedEventArgs e) {
|
|
if ((sliderControl.Value - Step) > sliderControl.Minimum) {
|
|
sliderControl.Value -= Step;
|
|
}
|
|
else {
|
|
sliderControl.Value = sliderControl.Minimum;
|
|
}
|
|
}
|
|
|
|
private void OnPlusBtnClicked(object sender, RoutedEventArgs e) {
|
|
if ((sliderControl.Value + Step) < sliderControl.Maximum) {
|
|
sliderControl.Value += Step;
|
|
}
|
|
else {
|
|
sliderControl.Value = sliderControl.Maximum;
|
|
}
|
|
}
|
|
}
|
|
}
|