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