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