-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageDisplayControl.xaml.cs
78 lines (69 loc) · 2.14 KB
/
MessageDisplayControl.xaml.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
using System;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
namespace RS.WPF.MessageDisplay;
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class MessageDisplayControl : UserControl
{
public MessageDisplayControl()
{
InitializeComponent();
}
private Exception Ex { get; set; }
private string Message { get; set; }
public void DisplayErrorMessage(string Message, Exception ex=null)
{
this.Message = Message;
this.Ex = ex;
this.StatusMessage.Content = Message;
this.StatusMessage.Foreground = Brushes.Maroon;
}
public void DisplaySuccessMessage(string Message)
{
this.Message = Message;
this.Ex = null;
this.StatusMessage.Content = Message;
this.StatusMessage.Foreground = Brushes.DarkGreen;
var timer = new DispatcherTimer
{
Interval = TimeSpan.FromSeconds(4.5)
};
timer.Tick +=
(o, e) =>
{
timer.Stop();
StatusMessage.Content = string.Empty;
};
timer.Start();
}
public void DisplayAnimatedMessage(string Message)
{
StatusMessage.Content = Message;
var animation = new ColorAnimation
{
From = Colors.Red,
To = Colors.SaddleBrown,
AutoReverse = true,
Duration = TimeSpan.FromSeconds(5),
RepeatBehavior= new RepeatBehavior(TimeSpan.FromSeconds(20))
};
StatusMessage.Foreground = new SolidColorBrush();
StatusMessage.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, animation);
}
public void Clear()
{
this.StatusMessage.Content = "";
this.Ex = null;
this.Message = "";
this.StatusMessage.Background = Brushes.Transparent;
}
private void StatusMessage_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
var MsgWindow = new DisplayMessageDetails(this.Message, Ex);
MsgWindow.ShowDialog();
}
}