WPF颜色特性标签Color
/*---------------------------------------------------------------- * 作 者 :姜 彦 * 项目名称 :EMRCPOE.Presentation.Common.Attributes * 类 名 称 :ColorAttribute * 命名空间 :EMRCPOE.Presentation.Common.Attributes * CLR 版本 :4.0.30319.42000 * 创建时间 :2019/11/6 16:00:10 * 当前版本 :1.0.0.0 * WeChatQQ :771078740 * My Email :jiangyan2008.521@gmail.com * jiangyan2008.521@qq.com * 描述说明 :色值特性 * * 修改历史 : * ******************************************************************* * Copyright @ JiangYan 2019. All rights reserved. ******************************************************************* ------------------------------------------------------------------*/ using EMRCPOE.Presentation.Common.BaseModel; using EMRCPOE.Presentation.Common.Enum; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Media; namespace EMRCPOE.Presentation.Common.Attributes { /// <summary> /// 色值特性 /// </summary> public class ColorAttribute:Attribute { #region Construction /// <summary> /// 色值特性 /// </summary> /// <param name="colorValue">通用WPF色值</param> public ColorAttribute(Color colorValue) { this._color = new SolidColorBrush(colorValue); } /// <summary> /// 色值特性 /// </summary> /// <param name="colorValue">十六进制色值字符串</param> public ColorAttribute(string colorValue) { this._color=new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorValue)); } #endregion #region Property private SolidColorBrush _color; /// <summary> /// 色值 /// </summary> public SolidColorBrush Color { get { return _color; } set { _color = value; } } #endregion Property } public static class ColorAttributeEx { /// <summary> /// 获取色值特性值 /// </summary> /// <typeparam name="T">泛型对象</typeparam> /// <param name="obj">泛型单个对象</param> /// <param name="expr">Lambda表达式</param> /// <returns></returns> public static SolidColorBrush Color<T>(this T obj, Expression<Func<T, object>> expr) { var strColorValue = string.Empty; if (expr.Body is UnaryExpression) { var body = (MemberExpression)((UnaryExpression)expr.Body).Operand; var attr = body.Member.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute)); if (attr == null) strColorValue = body.Member.Name; else strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString(); } else if (expr.Body is MemberExpression) { var body = expr.Body as MemberExpression; var attr = body.Member.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute)); if (attr == null) strColorValue = body.Member.Name; else strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString(); } else if (expr.Body is ParameterExpression) { var body = expr.Body as ParameterExpression; var attr = body.Type.CustomAttributes.FirstOrDefault(t => t.AttributeType == typeof(ColorAttribute)); if (attr == null) strColorValue = body.Type.Name; else strColorValue = attr.ConstructorArguments.FirstOrDefault().Value.ToString(); } return new SolidColorBrush((Color)ColorConverter.ConvertFromString(strColorValue)); } /// <summary> /// 获取色值特性值 /// </summary> /// <typeparam name="T">枚举类型</typeparam> /// <param name="obj">枚举值</param> /// <returns>特性的说明</returns> public static SolidColorBrush Color<T>(this T obj) { var type = obj.GetType(); FieldInfo field = type.GetField(System.Enum.GetName(type, obj)); ColorAttribute descAttr = Attribute.GetCustomAttribute(field, typeof(ColorAttribute)) as ColorAttribute; if (descAttr == null) { return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFF")); } return descAttr.Color; } } #region 医嘱状态管理 /// <summary> /// 表示医嘱状态事件数据的类,并提供用于不包含事件数据的事件的值 /// </summary> public class OrderStatusEventArgs : EventArgs { /// <summary> /// 医嘱时间类构造函数 /// </summary> /// <param name="previousOrderStatus">前一个状态</param> /// <param name="currentOrderStatus">当前状态</param> /// <param name="nextOrderStatus">下一个状态</param> public OrderStatusEventArgs(OrderStatusEnum previousOrderStatus, OrderStatusEnum currentOrderStatus, OrderStatusEnum nextOrderStatus) { this._previousOrderStatus = previousOrderStatus; this._currentOrderStatus = currentOrderStatus; this._nextOrderStatus = nextOrderStatus; } /// <summary> /// 医嘱时间类构造函数 /// </summary> /// <param name="previousOrderStatus">前一个状态</param> /// <param name="currentOrderStatus">当前状态</param> public OrderStatusEventArgs(OrderStatusEnum previousOrderStatus, OrderStatusEnum currentOrderStatus) { this._previousOrderStatus = previousOrderStatus; this._currentOrderStatus = currentOrderStatus; } private OrderStatusEnum _previousOrderStatus; /// <summary> /// 前一个医嘱状态 /// </summary> public OrderStatusEnum PreviousOrderStatus { get { return _previousOrderStatus; } set { _previousOrderStatus = value; } } private OrderStatusEnum _currentOrderStatus; /// <summary> /// 当前医嘱状态 /// </summary> public OrderStatusEnum CurrentOrderStatus { get { return _currentOrderStatus; } set { _currentOrderStatus = value; } } private OrderStatusEnum _nextOrderStatus; /// <summary> /// 下一个医嘱状态 /// </summary> public OrderStatusEnum NextOrderStatus { get { return _nextOrderStatus; } set { _nextOrderStatus = value; } } } /// <summary> /// 医嘱状态管理类 /// </summary> public class OrderStatusManager : Singleton<OrderStatusManager> { #region Property private OrderStatusEnum _orderStatus; /// <summary> /// 医嘱状态 /// </summary> public OrderStatusEnum OrderStatus { get { return _orderStatus; } set { OrderStatusChanged(this, new OrderStatusEventArgs(_orderStatus, value)); _orderStatus = value; } } #endregion #region Event /// <summary> /// 医嘱状态监控委托 /// </summary> /// <param name="sender"></param> /// <param name="e">医嘱状态事件数据</param> public delegate void MonitoredEventHandler(object sender, OrderStatusEventArgs e); /// <summary> /// 医嘱监控事件 /// </summary> public event MonitoredEventHandler Monitored; /// <summary> /// 医嘱状态监控事件触发 /// </summary> /// <param name="e"></param> public void Invoke(object sender, OrderStatusEventArgs e) { if (Monitored != null) Monitored(sender, e); } #endregion #region Function /// <summary> /// 医嘱状态改变 /// </summary> /// <param name="e"></param> private void OrderStatusChanged(object sender, OrderStatusEventArgs e) { Invoke(this, e); } #endregion } #endregion } /*---------------------------------------------------------------- * 备 注 : * * * ******************************************************************* * Copyright @ JiangYan 2019. All rights reserved. ******************************************************************* ------------------------------------------------------------------*/
您的资助是我最大的动力!
金额随意,欢迎来赏!
我写的东西能让你能懂,那是义务
毕竟占用了你生命中的宝贵的时间和注意力
要是你还能喜欢我的作品,那就是缘分了
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的因为,我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【青青子衿】!