2 /* -----------------------------------------------------------------------
\r
3 * <copyright file="PithosBalloon.xaml.cs" company="GRNet">
\r
5 * Copyright 2011-2012 GRNET S.A. All rights reserved.
\r
7 * Redistribution and use in source and binary forms, with or
\r
8 * without modification, are permitted provided that the following
\r
9 * conditions are met:
\r
11 * 1. Redistributions of source code must retain the above
\r
12 * copyright notice, this list of conditions and the following
\r
15 * 2. Redistributions in binary form must reproduce the above
\r
16 * copyright notice, this list of conditions and the following
\r
17 * disclaimer in the documentation and/or other materials
\r
18 * provided with the distribution.
\r
21 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
32 * POSSIBILITY OF SUCH DAMAGE.
\r
34 * The views and conclusions contained in the software and
\r
35 * documentation are those of the authors and should not be
\r
36 * interpreted as representing official policies, either expressed
\r
37 * or implied, of GRNET S.A.
\r
39 * -----------------------------------------------------------------------
\r
43 using System.Collections.Generic;
\r
46 using System.Windows;
\r
47 using System.Windows.Controls;
\r
48 using System.Windows.Controls.Primitives;
\r
49 using System.Windows.Data;
\r
50 using System.Windows.Documents;
\r
51 using System.Windows.Input;
\r
52 using System.Windows.Media;
\r
53 using System.Windows.Media.Imaging;
\r
54 using System.Windows.Navigation;
\r
55 using System.Windows.Shapes;
\r
56 using Hardcodet.Wpf.TaskbarNotification;
\r
58 namespace Pithos.Client.WPF.Shell
\r
61 /// Interaction logic for PithosBalloon.xaml
\r
63 public partial class PithosBalloon : UserControl
\r
65 private bool isClosing = false;
\r
67 #region Message dependency property
\r
69 public static readonly DependencyProperty MessageProperty =
\r
70 DependencyProperty.Register("Message",
\r
72 typeof (PithosBalloon),
\r
73 new FrameworkPropertyMetadata(""));
\r
74 public static readonly DependencyProperty TitleProperty =
\r
75 DependencyProperty.Register("Title",
\r
77 typeof (PithosBalloon),
\r
78 new FrameworkPropertyMetadata(""));
\r
79 public static readonly DependencyProperty IconProperty =
\r
80 DependencyProperty.Register("Icon",
\r
81 typeof (BalloonIcon),
\r
82 typeof (PithosBalloon),
\r
83 new FrameworkPropertyMetadata(BalloonIcon.None));
\r
85 public string Message
\r
87 get { return (string) GetValue(MessageProperty); }
\r
88 set { SetValue(MessageProperty, value); }
\r
91 public BalloonIcon Icon
\r
93 get { return (BalloonIcon) GetValue(IconProperty); }
\r
95 SetValue(IconProperty, value);
\r
101 get { return (string) GetValue(TitleProperty); }
\r
102 set { SetValue(TitleProperty, value); }
\r
110 public PithosBalloon()
\r
112 InitializeComponent();
\r
113 this.DataContext = this;
\r
114 TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing);
\r
119 /// By subscribing to the <see cref="TaskbarIcon.BalloonClosingEvent"/>
\r
120 /// and setting the "Handled" property to true, we suppress the popup
\r
121 /// from being closed in order to display the fade-out animation.
\r
123 private void OnBalloonClosing(object sender, RoutedEventArgs e)
\r
131 /// Resolves the <see cref="TaskbarIcon"/> that displayed
\r
132 /// the balloon and requests a close action.
\r
134 private void imgClose_MouseDown(object sender, MouseButtonEventArgs e)
\r
136 //the tray icon assigned this attached property to simplify access
\r
137 TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
\r
138 taskbarIcon.CloseBalloon();
\r
142 /// If the users hovers over the balloon, we don't close it.
\r
144 private void grid_MouseEnter(object sender, MouseEventArgs e)
\r
146 //if we're already running the fade-out animation, do not interrupt anymore
\r
147 //(makes things too complicated for the sample)
\r
148 if (isClosing) return;
\r
150 //the tray icon assigned this attached property to simplify access
\r
151 TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
\r
152 taskbarIcon.ResetBalloonCloseTimer();
\r
157 /// Closes the popup once the fade-out animation completed.
\r
158 /// The animation was triggered in XAML through the attached
\r
159 /// BalloonClosing event.
\r
161 private void OnFadeOutCompleted(object sender, EventArgs e)
\r
163 Popup pp = (Popup)Parent;
\r