using System.Windows.Controls; using System.Windows; namespace BPA.UIControl { /// /// 消通知容器 /// [TemplatePart(Name = StackPanelName, Type = typeof(StackPanel))] public class NotificationContainer : ContentControl { /// /// 消息堆叠面板名称 /// public const string StackPanelName = "PART_StackPanel"; private StackPanel stackPanel; static NotificationContainer() { DefaultStyleKeyProperty.OverrideMetadata(typeof(NotificationContainer), new FrameworkPropertyMetadata(typeof(NotificationContainer))); } /// public override void OnApplyTemplate() { base.OnApplyTemplate(); stackPanel = GetTemplateChild(StackPanelName) as StackPanel; } /// /// 标识 /// public static readonly DependencyProperty IdentifierProperty = DependencyProperty.Register("Identifier", typeof(string), typeof(NotificationContainer), new PropertyMetadata(default(string), OnIdentifierChanged)); /// /// 标识 /// public string Identifier { get { return (string)GetValue(IdentifierProperty); } set { SetValue(IdentifierProperty, value); } } private static void OnIdentifierChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is NotificationContainer container) { string identify = e.NewValue.ToString(); Notification.UpdateContainer(container, identify); } } /// /// 添加卡片 /// /// 消息卡片 internal void AddCard(NotificationCard card) { stackPanel.Children.Insert(0, card); } /// /// 移除卡片 /// /// internal void RemoveCard(NotificationCard card) { stackPanel.Children.Remove(card); } } }