This commit is contained in:
ShrlAlgo
2025-08-20 12:10:35 +08:00
parent fcd306b0f7
commit 955a01f564
962 changed files with 7893 additions and 127784 deletions

View File

@@ -1,7 +1,7 @@
using System.Windows.Controls.Primitives;
using System.Windows.Markup;
namespace NeumUI.Controls;
namespace NeoUI.Controls;
/// <summary>
/// Alert component for feedback.
@@ -14,12 +14,15 @@ public class Alert : Control
private const string PART_Close = "PART_Close";
private ButtonBase close;
private ButtonBase? close;
#endregion
#region Events
/// <summary>
/// 当警告框即将关闭时触发的事件。
/// </summary>
public static readonly RoutedEvent ClosingEvent =
EventManager.RegisterRoutedEvent("Closing", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Alert));
@@ -48,6 +51,9 @@ public class Alert : Control
#region Properties
/// <summary>
/// 表示警报控件是否显示为横幅样式。
/// </summary>
public static readonly DependencyProperty BannerProperty =
DependencyProperty.Register(nameof(Banner), typeof(bool), typeof(Alert), new PropertyMetadata(false));
@@ -60,6 +66,10 @@ public class Alert : Control
set => SetValue(BannerProperty, value);
}
/// <summary>
/// 表示警报是否可以关闭的依赖属性。
/// 该属性允许设置或获取一个布尔值,用于控制警报组件是否显示关闭按钮。
/// </summary>
public static readonly DependencyProperty ClosableProperty =
DependencyProperty.Register(nameof(Closable), typeof(bool?), typeof(Alert), new PropertyMetadata(null, OnClosableChanged));
@@ -74,18 +84,19 @@ public class Alert : Control
private static void OnClosableChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as Alert).SetCloseButtonVisibility();
(d as Alert)?.SetCloseButtonVisibility();
}
private void SetCloseButtonVisibility()
{
if (close != null)
{
var visible = Closable.HasValue ? Closable.Value : CloseText != null;
close.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
if (close == null) return;
var visible = Closable ?? CloseText != null;
close.Visibility = visible ? Visibility.Visible : Visibility.Collapsed;
}
/// <summary>
/// 用于获取或设置关闭按钮的文本内容。
/// </summary>
public static readonly DependencyProperty CloseTextProperty =
DependencyProperty.Register(nameof(CloseText), typeof(object), typeof(Alert), new PropertyMetadata(null, OnCloseTextChanged));
@@ -100,19 +111,22 @@ public class Alert : Control
private static void OnCloseTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
(d as Alert).SetCloseButton();
(d as Alert)?.SetCloseButton();
}
private void SetCloseButton()
{
if (close != null)
{
close.Content = CloseText != null ? CloseText : new SymbolIcon() { Symbol = Assets.MaterialSymbol.Close };
close.Content = CloseText != null ? CloseText : new IconElement() { Symbol = Assets.MaterialSymbol.Close };
}
SetCloseButtonVisibility();
}
/// <summary>
/// 用于获取或设置警报的描述内容。
/// </summary>
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register(nameof(Description), typeof(object), typeof(Alert), new PropertyMetadata(null));
@@ -125,11 +139,14 @@ public class Alert : Control
set => SetValue(DescriptionProperty, value);
}
/// <summary>
/// 用于获取或设置警报图标名称的依赖属性。此属性允许自定义警报中显示的图标,通常用来表示警报的不同类型或状态。
/// </summary>
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(nameof(Icon), typeof(string), typeof(Alert), new PropertyMetadata(string.Empty));
/// <summary>
/// Gets/sets the icon type of the alert.
/// 获取或设置警报的图标。
/// </summary>
public string Icon
{
@@ -137,6 +154,9 @@ public class Alert : Control
set => SetValue(IconProperty, value);
}
/// <summary>
/// 用于获取或设置警告控件中显示的消息内容。
/// </summary>
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register(nameof(Message), typeof(object), typeof(Alert), new PropertyMetadata(null));
@@ -149,6 +169,9 @@ public class Alert : Control
set => SetValue(MessageProperty, value);
}
/// <summary>
/// 用于控制是否显示图标的依赖属性。
/// </summary>
public static readonly DependencyProperty ShowIconProperty =
DependencyProperty.Register(nameof(ShowIcon), typeof(bool), typeof(Alert), new PropertyMetadata(true));
@@ -161,6 +184,9 @@ public class Alert : Control
set => SetValue(ShowIconProperty, value);
}
/// <summary>
/// 获取或设置警报的外观类型。
/// </summary>
public static readonly DependencyProperty TypeProperty =
DependencyProperty.Register(nameof(Type), typeof(AppearanceType), typeof(Alert), new PropertyMetadata(AppearanceType.Info));
@@ -173,6 +199,9 @@ public class Alert : Control
set => SetValue(TypeProperty, value);
}
/// <summary>
/// 用于设置或获取图标颜色的画刷属性。
/// </summary>
public static readonly DependencyProperty IconBrushProperty =
DependencyProperty.Register(nameof(IconBrush), typeof(Brush), typeof(Alert), new PropertyMetadata(null));
@@ -198,6 +227,7 @@ public class Alert : Control
#region Overrides
/// <inheritdoc />
public override void OnApplyTemplate()
{
base.OnApplyTemplate();