root / trunk / Pithos.Client.WPF / Shell / PithosBalloon.xaml.cs @ fb9d6e00
History | View | Annotate | Download (3.4 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Windows; |
6 |
using System.Windows.Controls; |
7 |
using System.Windows.Controls.Primitives; |
8 |
using System.Windows.Data; |
9 |
using System.Windows.Documents; |
10 |
using System.Windows.Input; |
11 |
using System.Windows.Media; |
12 |
using System.Windows.Media.Imaging; |
13 |
using System.Windows.Navigation; |
14 |
using System.Windows.Shapes; |
15 |
using Hardcodet.Wpf.TaskbarNotification; |
16 |
|
17 |
namespace Pithos.Client.WPF.Shell |
18 |
{ |
19 |
/// <summary> |
20 |
/// Interaction logic for PithosBalloon.xaml |
21 |
/// </summary> |
22 |
public partial class PithosBalloon : UserControl |
23 |
{ |
24 |
private bool isClosing = false; |
25 |
|
26 |
#region BalloonText dependency property |
27 |
|
28 |
/// <summary> |
29 |
/// Description |
30 |
/// </summary> |
31 |
public static readonly DependencyProperty BalloonTextProperty = |
32 |
DependencyProperty.Register("BalloonText", |
33 |
typeof (string), |
34 |
typeof (PithosBalloon), |
35 |
new FrameworkPropertyMetadata("")); |
36 |
|
37 |
/// <summary> |
38 |
/// A property wrapper for the <see cref="BalloonTextProperty"/> |
39 |
/// dependency property:<br/> |
40 |
/// Description |
41 |
/// </summary> |
42 |
public string BalloonText |
43 |
{ |
44 |
get { return (string) GetValue(BalloonTextProperty); } |
45 |
set { SetValue(BalloonTextProperty, value); } |
46 |
} |
47 |
|
48 |
#endregion |
49 |
|
50 |
|
51 |
public PithosBalloon() |
52 |
{ |
53 |
InitializeComponent(); |
54 |
TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing); |
55 |
} |
56 |
|
57 |
|
58 |
/// <summary> |
59 |
/// By subscribing to the <see cref="TaskbarIcon.BalloonClosingEvent"/> |
60 |
/// and setting the "Handled" property to true, we suppress the popup |
61 |
/// from being closed in order to display the fade-out animation. |
62 |
/// </summary> |
63 |
private void OnBalloonClosing(object sender, RoutedEventArgs e) |
64 |
{ |
65 |
e.Handled = true; |
66 |
isClosing = true; |
67 |
} |
68 |
|
69 |
|
70 |
/// <summary> |
71 |
/// Resolves the <see cref="TaskbarIcon"/> that displayed |
72 |
/// the balloon and requests a close action. |
73 |
/// </summary> |
74 |
private void imgClose_MouseDown(object sender, MouseButtonEventArgs e) |
75 |
{ |
76 |
//the tray icon assigned this attached property to simplify access |
77 |
TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this); |
78 |
taskbarIcon.CloseBalloon(); |
79 |
} |
80 |
|
81 |
/// <summary> |
82 |
/// If the users hovers over the balloon, we don't close it. |
83 |
/// </summary> |
84 |
private void grid_MouseEnter(object sender, MouseEventArgs e) |
85 |
{ |
86 |
//if we're already running the fade-out animation, do not interrupt anymore |
87 |
//(makes things too complicated for the sample) |
88 |
if (isClosing) return; |
89 |
|
90 |
//the tray icon assigned this attached property to simplify access |
91 |
TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this); |
92 |
taskbarIcon.ResetBalloonCloseTimer(); |
93 |
} |
94 |
|
95 |
|
96 |
/// <summary> |
97 |
/// Closes the popup once the fade-out animation completed. |
98 |
/// The animation was triggered in XAML through the attached |
99 |
/// BalloonClosing event. |
100 |
/// </summary> |
101 |
private void OnFadeOutCompleted(object sender, EventArgs e) |
102 |
{ |
103 |
Popup pp = (Popup)Parent; |
104 |
pp.IsOpen = false; |
105 |
} |
106 |
} |
107 |
} |