Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Shell / PithosBalloon.xaml.cs @ 2dc6f765

History | View | Annotate | Download (4.1 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 Message dependency property
27
  
28
      public static readonly DependencyProperty MessageProperty =
29
          DependencyProperty.Register("Message",
30
                                      typeof (string),
31
                                      typeof (PithosBalloon),
32
                                      new FrameworkPropertyMetadata(""));
33
      public static readonly DependencyProperty TitleProperty =
34
          DependencyProperty.Register("Title",
35
                                      typeof (string),
36
                                      typeof (PithosBalloon),
37
                                      new FrameworkPropertyMetadata(""));
38
      public static readonly DependencyProperty IconProperty =
39
          DependencyProperty.Register("Icon",
40
                                      typeof (BalloonIcon),
41
                                      typeof (PithosBalloon),
42
                                      new FrameworkPropertyMetadata(BalloonIcon.None));
43
  
44
      public string Message
45
      {
46
        get { return (string) GetValue(MessageProperty); }
47
        set { SetValue(MessageProperty, value); }
48
      }
49

    
50
      public BalloonIcon Icon
51
      {
52
        get { return (BalloonIcon) GetValue(IconProperty); }
53
        set { 
54
            SetValue(IconProperty, value);            
55
        }
56
      }
57

    
58
        public string Title
59
      {
60
        get { return (string) GetValue(TitleProperty); }
61
        set { SetValue(TitleProperty, value); }
62
      }
63
  
64

    
65
       
66
      #endregion
67

    
68

    
69
      public PithosBalloon()
70
      {
71
        InitializeComponent();
72
          this.DataContext = this;
73
        TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing);
74
      }
75
  
76
  
77
      /// <summary>
78
      /// By subscribing to the <see cref="TaskbarIcon.BalloonClosingEvent"/>
79
      /// and setting the "Handled" property to true, we suppress the popup
80
      /// from being closed in order to display the fade-out animation.
81
      /// </summary>
82
      private void OnBalloonClosing(object sender, RoutedEventArgs e)
83
      {
84
        e.Handled = true;
85
        isClosing = true;
86
      }
87
  
88
  
89
      /// <summary>
90
      /// Resolves the <see cref="TaskbarIcon"/> that displayed
91
      /// the balloon and requests a close action.
92
      /// </summary>
93
      private void imgClose_MouseDown(object sender, MouseButtonEventArgs e)
94
      {
95
        //the tray icon assigned this attached property to simplify access
96
        TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
97
        taskbarIcon.CloseBalloon();
98
      }
99
  
100
      /// <summary>
101
      /// If the users hovers over the balloon, we don't close it.
102
      /// </summary>
103
      private void grid_MouseEnter(object sender, MouseEventArgs e)
104
      {
105
        //if we're already running the fade-out animation, do not interrupt anymore
106
        //(makes things too complicated for the sample)
107
        if (isClosing) return;
108
  
109
        //the tray icon assigned this attached property to simplify access
110
        TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this);
111
        taskbarIcon.ResetBalloonCloseTimer();
112
      }
113
  
114
  
115
      /// <summary>
116
      /// Closes the popup once the fade-out animation completed.
117
      /// The animation was triggered in XAML through the attached
118
      /// BalloonClosing event.
119
      /// </summary>
120
      private void OnFadeOutCompleted(object sender, EventArgs e)
121
      {
122
        Popup pp = (Popup)Parent;
123
        pp.IsOpen = false;
124
      }
125
   }
126
}