123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- 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>
- /// PressureBlockControl.xaml 的交互逻辑
- /// </summary>
- public partial class PressureBlockControl : UserControl
- {
- #region 属性
- public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(PressureBlockControl),
- new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 数值
- /// </summary>
- public double Value
- {
- get
- {
- return (double)this.GetValue(ValueProperty);
- }
- set
- {
- this.SetValue(ValueProperty, value);
- }
- }
- public static readonly DependencyProperty ForeColorProperty = DependencyProperty.Register("ForeColor", typeof(SolidColorBrush), typeof(PressureBlockControl),
- new FrameworkPropertyMetadata(new SolidColorBrush(Colors.Lime), FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 文字颜色
- /// </summary>
- public SolidColorBrush ForeColor
- {
- get
- {
- return (SolidColorBrush)this.GetValue(ForeColorProperty);
- }
- set
- {
- this.SetValue(ForeColorProperty, value);
- }
- }
- public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register("BackgroundColor", typeof(SolidColorBrush), typeof(PressureBlockControl),
- new FrameworkPropertyMetadata(new SolidColorBrush(Colors.Black), FrameworkPropertyMetadataOptions.AffectsRender));
- /// <summary>
- /// 背景颜色
- /// </summary>
- public SolidColorBrush BackgroundColor
- {
- get
- {
- return (SolidColorBrush)this.GetValue(BackgroundColorProperty);
- }
- set
- {
- this.SetValue(BackgroundColorProperty, value);
- }
- }
- public static readonly DependencyProperty IsWarningProperty = DependencyProperty.Register("IsWarning", typeof(bool), typeof(PressureBlockControl),
- new FrameworkPropertyMetadata(false, new PropertyChangedCallback(IsWarningPropertyChanged)));
- /// <summary>
- /// 是否告警
- /// </summary>
- public bool IsWarning
- {
- get
- {
- return (bool)this.GetValue(IsWarningProperty);
- }
- set
- {
- this.SetValue(IsWarningProperty, value);
- }
- }
- public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(PressureBlockControl),
- new FrameworkPropertyMetadata(false, new PropertyChangedCallback(IsErrorPropertyChanged)));
- /// <summary>
- /// 是否错误
- /// </summary>
- public bool IsError
- {
- get
- {
- return (bool)this.GetValue(IsErrorProperty);
- }
- set
- {
- this.SetValue(IsErrorProperty, value);
- }
- }
- private static void IsWarningPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if(e.NewValue!=null)
- {
- bool isWarning=(bool)e.NewValue;
- bool isError = (bool)d.GetValue(IsErrorProperty);
- if(isWarning)
- {
- if (!isError)
- {
- d.SetValue(BackgroundColorProperty, new SolidColorBrush(Colors.Yellow));
- d.SetValue(ForeColorProperty, new SolidColorBrush(Colors.Black));
- }
- }
- else
- {
- if (!isError)
- {
- d.SetValue(BackgroundColorProperty, new SolidColorBrush(Colors.Black));
- d.SetValue(ForeColorProperty, new SolidColorBrush(Colors.Lime));
- }
- }
- }
- }
- private static void IsErrorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (e.NewValue != null)
- {
- bool isError = (bool)e.NewValue;
- bool isWarning = (bool)d.GetValue(IsWarningProperty);
- if (isError)
- {
- d.SetValue(BackgroundColorProperty, new SolidColorBrush(Colors.Red));
- d.SetValue(ForeColorProperty, new SolidColorBrush(Colors.Black));
- }
- else
- {
- if (!isWarning)
- {
- d.SetValue(BackgroundColorProperty, new SolidColorBrush(Colors.Black));
- d.SetValue(ForeColorProperty, new SolidColorBrush(Colors.Lime));
- }
- }
- }
- }
- #endregion
- public PressureBlockControl()
- {
- InitializeComponent();
- }
- }
- }
|