using System.Windows.Controls.Primitives; using System.Windows.Controls; using System.Windows.Media; using System.Windows; using BPA.UIControl.Commons.KnownBoxes; namespace BPA.UIControl { /// /// 通知卡片 /// [TemplatePart(Name = TransitionPartName, Type = typeof(Transition))] [TemplatePart(Name = CloseButtonName, Type = typeof(Button))] public class NotificationCard : ContentControl { /// /// 转换动画名称 /// public const string TransitionPartName = "Path_Transition"; /// /// 关闭按钮名称 /// public const string CloseButtonName = "PART_CloseButton"; static NotificationCard() { DefaultStyleKeyProperty.OverrideMetadata(typeof(NotificationCard), new FrameworkPropertyMetadata(typeof(NotificationCard))); } /// public override void OnApplyTemplate() { base.OnApplyTemplate(); if (GetTemplateChild(CloseButtonName) is ButtonBase closeButton) { closeButton.Click += (sender, e) => { if (!IsShow) { IsShow = true; } IsShow = false; }; } if (GetTemplateChild(TransitionPartName) is Transition transition) { transition.Closed += (sender, e) => { RoutedEventArgs eventArgs = new RoutedEventArgs(CloseEvent, this); this.RaiseEvent(eventArgs); }; } } #region 事件 /// /// 关闭消息事件 /// public static readonly RoutedEvent CloseEvent = EventManager.RegisterRoutedEvent("Close", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(NotificationCard)); /// /// 关闭消息事件 /// public event RoutedEventHandler Close { add { AddHandler(CloseEvent, value); } remove { RemoveHandler(CloseEvent, value); } } #endregion 事件 #region 依赖属性 /// /// 圆角半径 /// public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(NotificationCard), new PropertyMetadata(default(CornerRadius))); /// /// 圆角半径 /// public CornerRadius CornerRadius { get { return (CornerRadius)GetValue(CornerRadiusProperty); } set { SetValue(CornerRadiusProperty, value); } } /// /// 主题色 /// public static readonly DependencyProperty ThemeColorBrushProperty = DependencyProperty.Register("ThemeColorBrush", typeof(SolidColorBrush), typeof(NotificationCard), new PropertyMetadata(default(SolidColorBrush))); /// /// 主题色 /// public SolidColorBrush ThemeColorBrush { get { return (SolidColorBrush)GetValue(ThemeColorBrushProperty); } set { SetValue(ThemeColorBrushProperty, value); } } /// /// 通知类型 /// public static readonly DependencyProperty TypeProperty = DependencyProperty.Register("Type", typeof(NotificationType), typeof(NotificationCard), new PropertyMetadata(default(NotificationType))); /// /// 通知类型 /// public NotificationType Type { get { return (NotificationType)GetValue(TypeProperty); } set { SetValue(TypeProperty, value); } } /// /// 是否可清除 /// public static readonly DependencyProperty IsClearableProperty = DependencyProperty.Register("IsClearable", typeof(bool), typeof(NotificationCard), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// 是否可清除 /// public bool IsClearable { get { return (bool)GetValue(IsClearableProperty); } set { SetValue(IsClearableProperty, BooleanBoxes.Box(value)); } } /// /// 是否显示 /// public static readonly DependencyProperty IsShowProperty = DependencyProperty.Register("IsShow", typeof(bool), typeof(NotificationCard), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// 是否显示 /// public bool IsShow { get { return (bool)GetValue(IsShowProperty); } set { SetValue(IsShowProperty, BooleanBoxes.Box(value)); } } /// /// 标题 /// public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(NotificationCard), new PropertyMetadata(default(string))); /// /// 标题 /// public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } #endregion 依赖属性 } }