87 lines
3.0 KiB
C#
87 lines
3.0 KiB
C#
using System.ComponentModel;
|
||
|
||
namespace NeoUI.Controls.Decorations;
|
||
|
||
/// <summary>
|
||
/// 装饰基类,用于创建具有特定视觉效果的控件。
|
||
/// 该类扩展了ContentControl,提供了基础的装饰功能如强度调整和着色器启用。
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 此类定义了所有装饰控件共享的基本属性和行为。它允许开发者通过设置Intensity(强度)和ShaderEnabled(着色器启用)属性来控制装饰效果的表现。
|
||
/// 当控件的实际宽度发生变化时,会自动更新IsWidthGreaterThanHeight属性,以反映当前宽度是否大于高度。
|
||
/// </remarks>
|
||
public class DecorationBase : ContentControl
|
||
{
|
||
static DecorationBase()
|
||
{
|
||
DefaultStyleKeyProperty.OverrideMetadata(typeof(DecorationBase),
|
||
new FrameworkPropertyMetadata(typeof(DecorationBase)));
|
||
}
|
||
|
||
/// <inheritdoc />
|
||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
||
{
|
||
IsWidthGreaterThanHeight = ActualWidth > ActualHeight;
|
||
|
||
base.OnRenderSizeChanged(sizeInfo);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 着色器效果权重,范围0~1
|
||
/// </summary>
|
||
public double Intensity
|
||
{
|
||
get => (double)GetValue(IntensityProperty);
|
||
set => SetValue(IntensityProperty, value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 启用或禁用边框效果
|
||
/// </summary>
|
||
public bool ShaderEnabled
|
||
{
|
||
get => (bool)GetValue(ShaderEnabledProperty);
|
||
set => SetValue(ShaderEnabledProperty, value);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 指示控件的宽度是否大于其高度。此属性值会根据控件的实际尺寸变化自动更新。
|
||
/// </summary>
|
||
[ReadOnly(true)]
|
||
public bool IsWidthGreaterThanHeight
|
||
{
|
||
get => (bool)GetValue(IsWidthGreaterThanHeightProperty);
|
||
set => SetValue(IsWidthGreaterThanHeightProperty, value);
|
||
}
|
||
|
||
|
||
#region Dependency Properties
|
||
|
||
/// <summary>
|
||
/// 代表装饰效果强度的依赖属性,其值范围为0到1。默认值设为1.0,表示最大强度。
|
||
/// </summary>
|
||
public static readonly DependencyProperty IntensityProperty =
|
||
DependencyProperty.Register(nameof(Intensity),
|
||
typeof(double), typeof(DecorationBase),
|
||
new PropertyMetadata(1.0));
|
||
|
||
|
||
/// <summary>
|
||
/// 用于控制着色器效果是否启用的依赖属性。默认值为true,表示着色器效果是开启状态。
|
||
/// </summary>
|
||
public static readonly DependencyProperty ShaderEnabledProperty =
|
||
DependencyProperty.Register(nameof(ShaderEnabled),
|
||
typeof(bool), typeof(DecorationBase),
|
||
new PropertyMetadata(true));
|
||
|
||
/// <summary>
|
||
/// 用于标识控件宽度是否大于其高度的依赖属性。此属性值会根据控件的实际尺寸变化自动更新。
|
||
/// </summary>
|
||
public static readonly DependencyProperty IsWidthGreaterThanHeightProperty =
|
||
DependencyProperty.Register(nameof(IsWidthGreaterThanHeight),
|
||
typeof(bool), typeof(DecorationBase),
|
||
new PropertyMetadata(true));
|
||
|
||
#endregion
|
||
|
||
} |