Files
ShrlAlgoToolkit/Melskin/Controls/Toast/ToastControl.xaml.cs
2026-02-17 22:17:13 +08:00

92 lines
4.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.
namespace Melskin.Controls;
// 定义通知类型
/// <summary>
/// ToastControl 是一个自定义的 WPF 控件,用于在用户界面中显示简短的通知消息。它支持不同类型的通知(如成功、信息、警告和错误),并能够根据通知类型自动调整其视觉样式。
/// </summary>
public partial class ToastControl
{
/// <summary>
///
/// </summary>
public ToastControl()
{
InitializeComponent();
DataContext = this;
}
/// <summary>
/// 该依赖属性用于存储和获取ToastControl控件中显示的消息文本。通过设置此属性可以动态地更改用户界面上显示的通知消息内容。
/// </summary>
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
nameof(Message), typeof(string), typeof(ToastControl), new PropertyMetadata(string.Empty, OnMessageChanged));
/// <summary>
/// 该依赖属性用于存储和获取ToastControl控件中显示的通知类型。通过设置此属性可以指定通知的种类如成功、信息、警告或错误从而影响通知的视觉表现比如颜色和图标。
/// </summary>
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
nameof(Type), typeof(ToastType), typeof(ToastControl), new PropertyMetadata(ToastType.Info/*, OnTypeChanged*/));
/// <summary>
/// 用于获取或设置ToastControl控件中显示的消息文本。通过更改此属性可以动态更新用户界面上的通知消息内容。
/// </summary>
public string Message
{
get => (string)GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
/// <summary>
/// 该依赖属性用于存储和获取ToastControl控件中显示的通知类型。通过设置此属性可以指定通知的种类如成功、信息、错误或警告从而影响用户界面上通知的视觉呈现方式。
/// </summary>
public ToastType Type
{
get => (ToastType)GetValue(TypeProperty);
set => SetValue(TypeProperty, value);
}
private static void OnMessageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ToastControl)d).MessageTextBlock.Text = (string)e.NewValue;
}
// 当类型改变时,更新颜色和图标
//private static void OnTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
//{
// var control = (ToastControl)d;
// var icon = "";
// Brush background = Brushes.Gray;
// Brush foreground = Brushes.White;
// switch ((ToastType)e.NewValue)
// {
// case ToastType.Success:
// icon = "\uE930"; // Success icon
// background = new SolidColorBrush(Color.FromRgb(240, 249, 235));
// foreground = new SolidColorBrush(Color.FromRgb(103, 194, 58));
// break;
// case ToastType.Info:
// icon = "\uE946"; // Info icon
// background = new SolidColorBrush(Color.FromRgb(237, 246, 253));
// foreground = new SolidColorBrush(Color.FromRgb(64, 158, 255));
// break;
// case ToastType.Warning:
// icon = "\uE7BA"; // Warning icon
// background = new SolidColorBrush(Color.FromRgb(253, 246, 236));
// foreground = new SolidColorBrush(Color.FromRgb(230, 162, 60));
// break;
// case ToastType.Error:
// icon = "\uEA39"; // Error icon
// background = new SolidColorBrush(Color.FromRgb(254, 242, 242));
// foreground = new SolidColorBrush(Color.FromRgb(245, 108, 108));
// break;
// }
// control.IconTextBlock.Text = icon;
// control.IconTextBlock.Foreground = foreground;
// control.RootBorder.Background = background;
// control.RootBorder.BorderBrush = background;
//}
}