-
Notifications
You must be signed in to change notification settings - Fork 168
/
NotificationDisplayPart.cs
82 lines (72 loc) · 2.46 KB
/
NotificationDisplayPart.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using ToastNotifications.Display;
using ToastNotifications.Utilities;
namespace ToastNotifications.Core
{
public abstract class NotificationDisplayPart : UserControl
{
protected INotificationAnimator Animator;
public INotification Notification { get; protected set; }
protected NotificationDisplayPart()
{
Animator = new NotificationAnimator(this, TimeSpan.FromMilliseconds(300), TimeSpan.FromMilliseconds(300));
Margin = new Thickness(1);
Animator.Setup();
Loaded += OnLoaded;
MinHeight = 60;
}
protected override void OnMouseEnter(MouseEventArgs e)
{
var options = Notification.Options;
if (options != null && options.FreezeOnMouseEnter)
{
if (!options.UnfreezeOnMouseLeave) // message stay freezed, show close button
{
var bord2 = Content as Border;
if (bord2 != null)
{
if (Notification.CanClose)
{
Notification.CanClose = false;
var btn = this.FindChild<Button>("CloseButton");
if (btn != null)
{
btn.Visibility = Visibility.Visible;
}
}
}
}
else
{
Notification.CanClose = false;
}
}
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(MouseEventArgs e)
{
var opts = Notification.Options;
if (opts != null && opts.FreezeOnMouseEnter && opts.UnfreezeOnMouseLeave)
{
Notification.CanClose = true;
}
base.OnMouseLeave(e);
}
public void Bind<TNotification>(TNotification notification) where TNotification : INotification
{
Notification = notification;
DataContext = Notification;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
Animator.PlayShowAnimation();
}
public void OnClose()
{
Animator.PlayHideAnimation();
}
}
}