using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls.Primitives; using Melskin.Controls; namespace Melskin.Assists { /// /// 颜色辅助类,提供了一组附加属性,用于在WPF应用程序中为控件设置和获取各种颜色相关的属性,如标题栏背景色、鼠标悬停颜色、聚焦颜色和按下状态颜色等。 /// public static class ColorAssist { /// /// 获取指定依赖对象的标题栏背景画刷。 /// /// 要获取其标题栏背景画刷的依赖对象。 /// 与指定依赖对象关联的标题栏背景画刷。 [AttachedPropertyBrowsableForType(typeof(MelWindow))] public static Brush GetTitleBarBackground(DependencyObject obj) { return (Brush)obj.GetValue(TitleBarBackgroundProperty); } /// /// 设置指定依赖对象的标题栏背景画刷。 /// /// 要设置标题栏背景的依赖对象。 /// 作为标题栏背景的新画刷值。 public static void SetTitleBarBackground(DependencyObject obj, Brush value) { obj.SetValue(TitleBarBackgroundProperty, value); } /// /// 用于定义依赖属性的标识符,该属性允许设置和获取与窗口控件关联的标题栏背景画刷。此属性可以应用于任何实现了DependencyObject接口的对象上,以便自定义其标题栏背景颜色。 /// public static readonly DependencyProperty TitleBarBackgroundProperty = DependencyProperty.RegisterAttached("TitleBarBackground", typeof(Brush), typeof(ColorAssist)); #region Brushes /// /// 代表当鼠标悬停在控件上时前景色的属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停状态下的前景色刷。 /// public static readonly DependencyProperty MouseOverForegroundProperty = DependencyProperty.RegisterAttached( "MouseOverForeground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取与指定依赖对象关联的鼠标悬停前景色。 /// /// 要获取其鼠标悬停前景色属性的依赖对象。 /// 与指定依赖对象关联的鼠标悬停前景色。 public static Brush GetMouseOverForeground(DependencyObject obj) { return (Brush)obj.GetValue(MouseOverForegroundProperty); } /// /// 设置指定依赖对象在鼠标悬停时的前景色。 /// /// 要设置其鼠标悬停前景色属性的依赖对象。 /// 表示鼠标悬停时前景色的Brush对象。 public static void SetMouseOverForeground(DependencyObject obj, Brush value) { obj.SetValue(MouseOverForegroundProperty, value); } /// /// 代表当鼠标悬停在控件上时边框的颜色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停状态下的边框画刷。 /// public static readonly DependencyProperty MouseOverBorderBrushProperty = DependencyProperty.RegisterAttached( "MouseOverBorderBrush", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的鼠标悬停时边框画刷。 /// /// 要获取其鼠标悬停时边框画刷属性的依赖对象。 /// 指定依赖对象的鼠标悬停时边框画刷。 public static Brush GetMouseOverBorderBrush(DependencyObject obj) { return (Brush)obj.GetValue(MouseOverBorderBrushProperty); } /// /// 设置指定依赖对象的鼠标悬停边框画刷。 /// /// 要设置其鼠标悬停边框画刷属性的依赖对象。 /// 要应用到依赖对象上的鼠标悬停边框画刷。 public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value) { obj.SetValue(MouseOverBorderBrushProperty, value); } /// /// 代表控件在鼠标悬停时的背景画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停时的背景颜色或图案。 /// public static readonly DependencyProperty MouseOverBackgroundProperty = DependencyProperty.RegisterAttached( "MouseOverBackground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的鼠标悬停时的背景画刷。 /// /// 要获取其鼠标悬停背景画刷属性的依赖对象。 /// 指定依赖对象的鼠标悬停背景画刷。 public static Brush GetMouseOverBackground(DependencyObject obj) { return (Brush)obj.GetValue(MouseOverBackgroundProperty); } /// /// 设置指定依赖对象的鼠标悬停背景画刷。 /// /// 要设置其鼠标悬停背景画刷属性的依赖对象。 /// 新的鼠标悬停背景画刷值。 public static void SetMouseOverBackground(DependencyObject obj, Brush value) { obj.SetValue(MouseOverBackgroundProperty, value); } /// /// 代表控件在获得焦点时的前景色属性。此依赖属性允许为WPF应用程序中的控件设置和获取焦点状态下的前景色,支持继承,并影响渲染。 /// public static readonly DependencyProperty FocusedForegroundProperty = DependencyProperty.RegisterAttached( "FocusedForeground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取与指定依赖对象关联的聚焦前景色。 /// /// 要获取其聚焦前景色属性的依赖对象。 /// 与指定依赖对象关联的聚焦前景色。 public static Brush GetFocusedForeground(DependencyObject obj) { return (Brush)obj.GetValue(FocusedForegroundProperty); } /// /// 设置指定依赖对象的聚焦前景色。 /// /// 要设置其聚焦前景色属性的依赖对象。 /// 新聚焦前景色值。 public static void SetFocusedForeground(DependencyObject obj, Brush value) { obj.SetValue(FocusedForegroundProperty, value); } /// /// 代表控件在获得焦点时边框的画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取焦点状态下的边框画刷。 /// public static readonly DependencyProperty FocusedBorderBrushProperty = DependencyProperty.RegisterAttached( "FocusedBorderBrush", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取与指定依赖对象关联的聚焦边框画刷。 /// /// 要获取其聚焦边框画刷属性的依赖对象。 /// 与指定依赖对象关联的聚焦边框画刷。 public static Brush GetFocusedBorderBrush(DependencyObject obj) { return (Brush)obj.GetValue(FocusedBorderBrushProperty); } /// /// 设置指定依赖对象的焦点边框画刷。 /// /// 要设置其焦点边框画刷属性的依赖对象。 /// 要设置的焦点边框画刷值。 public static void SetFocusedBorderBrush(DependencyObject obj, Brush value) { obj.SetValue(FocusedBorderBrushProperty, value); } /// /// 代表控件获得焦点时的背景颜色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取当其处于焦点状态下的背景颜色,支持继承。 /// public static readonly DependencyProperty FocusedBackgroundProperty = DependencyProperty.RegisterAttached( "FocusedBackground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的聚焦背景画刷。 /// /// 要获取其聚焦背景画刷属性的依赖对象。 /// 指定依赖对象的聚焦背景画刷。 public static Brush GetFocusedBackground(DependencyObject obj) { return (Brush)obj.GetValue(FocusedBackgroundProperty); } /// /// 设置指定依赖对象的焦点背景。 /// /// 要设置其焦点背景属性的依赖对象。 /// 要设置的焦点背景画刷。 public static void SetFocusedBackground(DependencyObject obj, Brush value) { obj.SetValue(FocusedBackgroundProperty, value); } /// /// 代表控件被按下时的前景色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取按下的前景色,并且支持继承。 /// public static readonly DependencyProperty PressedForegroundProperty = DependencyProperty.RegisterAttached( "PressedForeground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的按下状态前景色。 /// /// 要获取其按下状态前景色属性的依赖对象。 /// 指定依赖对象的按下状态前景色。 public static Brush GetPressedForeground(DependencyObject obj) { return (Brush)obj.GetValue(PressedForegroundProperty); } /// /// 设置指定依赖对象的按下状态前景色。 /// /// 要设置其按下状态前景色属性的依赖对象。 /// 新的按下状态前景色。 public static void SetPressedForeground(DependencyObject obj, Brush value) { obj.SetValue(PressedForegroundProperty, value); } /// /// 代表控件在按下状态时的边框画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取按下状态下的边框颜色或纹理。 /// public static readonly DependencyProperty PressedBorderBrushProperty = DependencyProperty.RegisterAttached( "PressedBorderBrush", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的按下状态边框画刷。 /// /// 要获取其按下状态边框画刷属性的依赖对象。 /// 指定依赖对象的按下状态边框画刷。 public static Brush GetPressedBorderBrush(DependencyObject obj) { return (Brush)obj.GetValue(PressedBorderBrushProperty); } /// /// 设置指定依赖对象的按下状态边框画刷。 /// /// 要设置其按下状态边框画刷属性的依赖对象。 /// 要设置的按下状态边框画刷。 public static void SetPressedBorderBrush(DependencyObject obj, Brush value) { obj.SetValue(PressedBorderBrushProperty, value); } /// /// 代表控件在按下状态时的背景色属性。此依赖属性允许为WPF应用程序中的任意控件设置和获取按下状态时的背景颜色,支持继承并影响渲染。 /// public static readonly DependencyProperty PressedBackgroundProperty = DependencyProperty.RegisterAttached( "PressedBackground", typeof(Brush), typeof(ColorAssist), new FrameworkPropertyMetadata( Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits )); /// /// 获取指定依赖对象的按下背景画刷。 /// /// 要获取其按下背景画刷属性的依赖对象。 /// 指定依赖对象的按下背景画刷。 public static Brush GetPressedBackground(DependencyObject obj) { return (Brush)obj.GetValue(PressedBackgroundProperty); } /// /// 设置指定依赖对象的按下状态背景。 /// /// 要设置其按下状态背景的依赖对象。 /// 按下状态时使用的背景画刷。 public static void SetPressedBackground(DependencyObject obj, Brush value) { obj.SetValue(PressedBackgroundProperty, value); } #endregion } }