在用户控件中使用Notification弹窗

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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弹窗

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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));
}
}