Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/Decorations/DecorationBase.cs
ShrlAlgo 955a01f564 整理
2025-08-20 12:10:35 +08:00

87 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}