在用户控件中使用Notification弹窗
public partial class DemoView : UserControl
{
private WindowNotificationManager? _manager;
public DemoView()
{
InitializeComponent();
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
var topLevel = TopLevel.GetTopLevel(this);
_manager = new WindowNotificationManager(topLevel){ MaxItems = 5};
}
private void Button_OnClick(object? sender, RoutedEventArgs e)
{
_manager?.Show(new Notification("错误信息标题", "错误信息的内容!", NotificationType.Error));
}
}
在窗口中使用Notification弹窗
public partial class MainWindow : Window
{
private WindowNotificationManager? _manager;
public MainWindow()
{
InitializeComponent();
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_manager = new WindowNotificationManager(this) { MaxItems = 5 };
}
private void Button_OnClick(object? sender, RoutedEventArgs e)
{
_manager?.Show(new Notification("错误信息标题", "错误信息的内容!", NotificationType.Error));
}
}