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.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CyberX8_Themes.UserControls
{
///
/// GroupTextBoxControl.xaml 的交互逻辑
///
public partial class GroupDigitalBoxControl : UserControl
{
#region 属性
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 标题
///
public string Title
{
get
{
return (string)this.GetValue(TitleProperty);
}
set
{
this.SetValue(TitleProperty, value);
}
}
public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata("deg", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 单位
///
public string Unit
{
get
{
return (string)this.GetValue(UnitProperty);
}
set
{
this.SetValue(UnitProperty, value);
}
}
public static readonly DependencyProperty DigtalValueProperty = DependencyProperty.Register("DigitalValue", typeof(double), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata((double)-1, new PropertyChangedCallback(DigitalValueChanged)));
///
/// 数值
///
public double DigitalValue
{
get
{
return (double)this.GetValue(DigtalValueProperty);
}
set
{
this.SetValue(DigtalValueProperty, value);
}
}
///
/// 数值发生变化事件
///
///
///
private static void DigitalValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != null)
{
double newValue = (double)e.NewValue;
double minValue = (double)d.GetValue(MinValueProperty);
double maxValue = (double)d.GetValue(MaxValueProperty);
bool validResult = newValue >= minValue && newValue <= maxValue;
d.SetValue(ValidResultProperty, validResult);
}
}
public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register("MinValue", typeof(double), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 最小数值
///
public double MinValue
{
get
{
return (double)this.GetValue(MinValueProperty);
}
set
{
this.SetValue(MinValueProperty, value);
}
}
public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(double), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 最大数值
///
public double MaxValue
{
get
{
return (double)this.GetValue(MaxValueProperty);
}
set
{
this.SetValue(MaxValueProperty, value);
}
}
public static readonly DependencyProperty EnableProperty = DependencyProperty.Register("Enable", typeof(bool), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 可用性
///
public bool Enable
{
get
{
return (bool)this.GetValue(EnableProperty);
}
set
{
this.SetValue(EnableProperty, value);
}
}
public static readonly DependencyProperty ValidResultProperty = DependencyProperty.Register("ValidResult", typeof(bool), typeof(GroupDigitalBoxControl),
new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 合理性
///
public bool ValidResult
{
get
{
return (bool)this.GetValue(ValidResultProperty);
}
set
{
this.SetValue(ValidResultProperty, value);
}
}
#endregion
public GroupDigitalBoxControl()
{
InitializeComponent();
}
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
ValidResult = DigitalValue >= MinValue && DigitalValue <= MaxValue;
RectangleSetPoint.Fill = ValidResult? new SolidColorBrush(Colors.Transparent) : new SolidColorBrush(Colors.Yellow);
txtValue.Background = ValidResult? new SolidColorBrush(Colors.Transparent) : new SolidColorBrush(Colors.Yellow);
}
}
}