功能完善
This commit is contained in:
358
NeuWPF/NeoUI/Assists/ControlAssist.cs
Normal file
358
NeuWPF/NeoUI/Assists/ControlAssist.cs
Normal file
@@ -0,0 +1,358 @@
|
||||
|
||||
namespace NeumUI.Assists;
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
/// <summary>
|
||||
/// 提供各种控件的附加属性帮助类。
|
||||
/// </summary>
|
||||
public static class ControlAssist
|
||||
{
|
||||
#region Border
|
||||
|
||||
/// <summary>
|
||||
/// 获取与指定依赖对象关联的几何图形。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其几何图形属性的依赖对象。</param>
|
||||
/// <returns>与指定依赖对象关联的几何图形。</returns>
|
||||
public static Geometry GetGeometry(DependencyObject obj)
|
||||
{
|
||||
return (Geometry)obj.GetValue(GeometryProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置与指定依赖对象关联的几何图形。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其几何图形属性的依赖对象。</param>
|
||||
/// <param name="value">要与此依赖对象关联的新几何图形值。</param>
|
||||
public static void SetGeometry(DependencyObject obj, Geometry value)
|
||||
{
|
||||
obj.SetValue(GeometryProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表附加到控件的几何图形属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取几何图形。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty GeometryProperty =
|
||||
DependencyProperty.RegisterAttached("Geometry",
|
||||
typeof(Geometry), typeof(ControlAssist));
|
||||
|
||||
/// <summary>
|
||||
/// 代表附加到控件的圆角半径属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取圆角半径,影响控件的测量和渲染。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(
|
||||
"CornerRadius",
|
||||
typeof(CornerRadius),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
default(CornerRadius),
|
||||
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取与指定依赖对象关联的圆角半径。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其圆角半径属性的依赖对象。</param>
|
||||
/// <returns>与指定依赖对象关联的圆角半径。</returns>
|
||||
[Category("NeuAssists")]
|
||||
public static CornerRadius GetCornerRadius(DependencyObject obj)
|
||||
{
|
||||
return (CornerRadius)obj.GetValue(CornerRadiusProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a value that represents the degree to which the corners of a control border are rounded.
|
||||
/// </summary>
|
||||
public static void SetCornerRadius(DependencyObject obj, CornerRadius value)
|
||||
{
|
||||
obj.SetValue(CornerRadiusProperty, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Brushes
|
||||
|
||||
/// <summary>
|
||||
/// 代表当鼠标悬停在控件上时前景色的属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停状态下的前景色刷。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MouseOverForegroundProperty = DependencyProperty.RegisterAttached(
|
||||
"MouseOverForeground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取与指定依赖对象关联的鼠标悬停前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其鼠标悬停前景色属性的依赖对象。</param>
|
||||
/// <returns>与指定依赖对象关联的鼠标悬停前景色。</returns>
|
||||
public static Brush GetMouseOverForeground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(MouseOverForegroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象在鼠标悬停时的前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其鼠标悬停前景色属性的依赖对象。</param>
|
||||
/// <param name="value">表示鼠标悬停时前景色的Brush对象。</param>
|
||||
public static void SetMouseOverForeground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(MouseOverForegroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表当鼠标悬停在控件上时边框的颜色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停状态下的边框画刷。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MouseOverBorderBrushProperty = DependencyProperty.RegisterAttached(
|
||||
"MouseOverBorderBrush",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的鼠标悬停时边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其鼠标悬停时边框画刷属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的鼠标悬停时边框画刷。</returns>
|
||||
public static Brush GetMouseOverBorderBrush(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(MouseOverBorderBrushProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的鼠标悬停边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其鼠标悬停边框画刷属性的依赖对象。</param>
|
||||
/// <param name="value">要应用到依赖对象上的鼠标悬停边框画刷。</param>
|
||||
public static void SetMouseOverBorderBrush(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(MouseOverBorderBrushProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件在鼠标悬停时的背景画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取鼠标悬停时的背景颜色或图案。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MouseOverBackgroundProperty = DependencyProperty.RegisterAttached(
|
||||
"MouseOverBackground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的鼠标悬停时的背景画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其鼠标悬停背景画刷属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的鼠标悬停背景画刷。</returns>
|
||||
public static Brush GetMouseOverBackground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(MouseOverBackgroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的鼠标悬停背景画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其鼠标悬停背景画刷属性的依赖对象。</param>
|
||||
/// <param name="value">新的鼠标悬停背景画刷值。</param>
|
||||
public static void SetMouseOverBackground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(MouseOverBackgroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件在获得焦点时的前景色属性。此依赖属性允许为WPF应用程序中的控件设置和获取焦点状态下的前景色,支持继承,并影响渲染。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty FocusedForegroundProperty = DependencyProperty.RegisterAttached(
|
||||
"FocusedForeground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取与指定依赖对象关联的聚焦前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其聚焦前景色属性的依赖对象。</param>
|
||||
/// <returns>与指定依赖对象关联的聚焦前景色。</returns>
|
||||
public static Brush GetFocusedForeground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(FocusedForegroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的聚焦前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其聚焦前景色属性的依赖对象。</param>
|
||||
/// <param name="value">新聚焦前景色值。</param>
|
||||
public static void SetFocusedForeground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(FocusedForegroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件在获得焦点时边框的画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取焦点状态下的边框画刷。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty FocusedBorderBrushProperty = DependencyProperty.RegisterAttached(
|
||||
"FocusedBorderBrush",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取与指定依赖对象关联的聚焦边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其聚焦边框画刷属性的依赖对象。</param>
|
||||
/// <returns>与指定依赖对象关联的聚焦边框画刷。</returns>
|
||||
public static Brush GetFocusedBorderBrush(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(FocusedBorderBrushProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的焦点边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其焦点边框画刷属性的依赖对象。</param>
|
||||
/// <param name="value">要设置的焦点边框画刷值。</param>
|
||||
public static void SetFocusedBorderBrush(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(FocusedBorderBrushProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件获得焦点时的背景颜色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取当其处于焦点状态下的背景颜色,支持继承。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty FocusedBackgroundProperty = DependencyProperty.RegisterAttached(
|
||||
"FocusedBackground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的聚焦背景画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其聚焦背景画刷属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的聚焦背景画刷。</returns>
|
||||
public static Brush GetFocusedBackground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(FocusedBackgroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的焦点背景。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其焦点背景属性的依赖对象。</param>
|
||||
/// <param name="value">要设置的焦点背景画刷。</param>
|
||||
public static void SetFocusedBackground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(FocusedBackgroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件被按下时的前景色属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取按下的前景色,并且支持继承。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty PressedForegroundProperty = DependencyProperty.RegisterAttached(
|
||||
"PressedForeground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的按下状态前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其按下状态前景色属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的按下状态前景色。</returns>
|
||||
public static Brush GetPressedForeground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(PressedForegroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的按下状态前景色。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其按下状态前景色属性的依赖对象。</param>
|
||||
/// <param name="value">新的按下状态前景色。</param>
|
||||
public static void SetPressedForeground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(PressedForegroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件在按下状态时的边框画刷属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取按下状态下的边框颜色或纹理。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty PressedBorderBrushProperty = DependencyProperty.RegisterAttached(
|
||||
"PressedBorderBrush",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的按下状态边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其按下状态边框画刷属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的按下状态边框画刷。</returns>
|
||||
public static Brush GetPressedBorderBrush(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(PressedBorderBrushProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的按下状态边框画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其按下状态边框画刷属性的依赖对象。</param>
|
||||
/// <param name="value">要设置的按下状态边框画刷。</param>
|
||||
public static void SetPressedBorderBrush(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(PressedBorderBrushProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 代表控件在按下状态时的背景色属性。此依赖属性允许为WPF应用程序中的任意控件设置和获取按下状态时的背景颜色,支持继承并影响渲染。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty PressedBackgroundProperty = DependencyProperty.RegisterAttached(
|
||||
"PressedBackground",
|
||||
typeof(Brush),
|
||||
typeof(ControlAssist),
|
||||
new FrameworkPropertyMetadata(
|
||||
Brushes.Transparent, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits
|
||||
));
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定依赖对象的按下背景画刷。
|
||||
/// </summary>
|
||||
/// <param name="obj">要获取其按下背景画刷属性的依赖对象。</param>
|
||||
/// <returns>指定依赖对象的按下背景画刷。</returns>
|
||||
public static Brush GetPressedBackground(DependencyObject obj)
|
||||
{
|
||||
return (Brush)obj.GetValue(PressedBackgroundProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定依赖对象的按下状态背景。
|
||||
/// </summary>
|
||||
/// <param name="obj">要设置其按下状态背景的依赖对象。</param>
|
||||
/// <param name="value">按下状态时使用的背景画刷。</param>
|
||||
public static void SetPressedBackground(DependencyObject obj, Brush value)
|
||||
{
|
||||
obj.SetValue(PressedBackgroundProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user