123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- 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
- {
- /// <summary>
- /// GroupTextBoxControl.xaml 的交互逻辑
- /// </summary>
- public partial class GroupDigitalBoxControl : UserControl
- {
- #region 属性
- public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(GroupDigitalBoxControl),
- new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 标题
- /// </summary>
- 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));
- /// <summary>
- /// 单位
- /// </summary>
- 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)));
- /// <summary>
- /// 数值
- /// </summary>
- public double DigitalValue
- {
- get
- {
- return (double)this.GetValue(DigtalValueProperty);
- }
- set
- {
- this.SetValue(DigtalValueProperty, value);
- }
- }
- /// <summary>
- /// 数值发生变化事件
- /// </summary>
- /// <param name="d"></param>
- /// <param name="e"></param>
- 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));
- /// <summary>
- /// 最小数值
- /// </summary>
- 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));
- /// <summary>
- /// 最大数值
- /// </summary>
- 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));
- /// <summary>
- /// 可用性
- /// </summary>
- 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));
- /// <summary>
- /// 合理性
- /// </summary>
- 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);
- }
- }
- }
|