using System.Windows;
using System.Windows.Controls;
namespace BPA.UIControl
{
///
/// 消息容器
///
[TemplatePart(Name = MessageStackPanelName, Type = typeof(StackPanel))]
public class MessageContainer : ContentControl
{
///
/// 消息堆叠面板名称
///
public const string MessageStackPanelName = "PART_MessageStackPanel";
private StackPanel messageStackPanel;
static MessageContainer()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageContainer), new FrameworkPropertyMetadata(typeof(MessageContainer)));
}
///
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
messageStackPanel = GetTemplateChild(MessageStackPanelName) as StackPanel;
}
///
/// 标识
///
public static readonly DependencyProperty IdentifierProperty =
DependencyProperty.Register("Identifier", typeof(string), typeof(MessageContainer), 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 MessageContainer container)
{
string identify = e.NewValue.ToString();
Message.UpdateContainer(container, identify);
}
}
///
/// 添加消息卡片
///
/// 消息卡片
internal void AddMessageCard(MessageCard messageCard)
{
_ = messageStackPanel.Children.Add(messageCard);
}
///
/// 移除消息卡片
///
///
internal void RemoveMessageCard(MessageCard messageCard)
{
messageStackPanel.Children.Remove(messageCard);
}
}
}