#region /* ----------------------------------------------------------------------- * * * Copyright 2011-2012 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * 1. Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and * documentation are those of the authors and should not be * interpreted as representing official policies, either expressed * or implied, of GRNET S.A. * * ----------------------------------------------------------------------- */ #endregion using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Hardcodet.Wpf.TaskbarNotification; namespace Pithos.Client.WPF.Shell { /// /// Interaction logic for PithosBalloon.xaml /// public partial class PithosBalloon : UserControl { private bool isClosing = false; #region Message dependency property public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof (string), typeof (PithosBalloon), new FrameworkPropertyMetadata("")); public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof (string), typeof (PithosBalloon), new FrameworkPropertyMetadata("")); public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof (BalloonIcon), typeof (PithosBalloon), new FrameworkPropertyMetadata(BalloonIcon.None)); public string Message { get { return (string) GetValue(MessageProperty); } set { SetValue(MessageProperty, value); } } public BalloonIcon Icon { get { return (BalloonIcon) GetValue(IconProperty); } set { SetValue(IconProperty, value); } } public string Title { get { return (string) GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } } #endregion public PithosBalloon() { InitializeComponent(); this.DataContext = this; TaskbarIcon.AddBalloonClosingHandler(this, OnBalloonClosing); } /// /// By subscribing to the /// and setting the "Handled" property to true, we suppress the popup /// from being closed in order to display the fade-out animation. /// private void OnBalloonClosing(object sender, RoutedEventArgs e) { e.Handled = true; isClosing = true; } /// /// Resolves the that displayed /// the balloon and requests a close action. /// private void imgClose_MouseDown(object sender, MouseButtonEventArgs e) { //the tray icon assigned this attached property to simplify access CloseBalloon(); } private void CloseBalloon() { TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this); taskbarIcon.CloseBalloon(); } /// /// If the users hovers over the balloon, we don't close it. /// private void grid_MouseEnter(object sender, MouseEventArgs e) { //if we're already running the fade-out animation, do not interrupt anymore //(makes things too complicated for the sample) if (isClosing) return; //the tray icon assigned this attached property to simplify access TaskbarIcon taskbarIcon = TaskbarIcon.GetParentTaskbarIcon(this); taskbarIcon.ResetBalloonCloseTimer(); } /// /// Closes the popup once the fade-out animation completed. /// The animation was triggered in XAML through the attached /// BalloonClosing event. /// private void OnFadeOutCompleted(object sender, EventArgs e) { Popup pp = (Popup)Parent; pp.IsOpen = false; } private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e) { CloseBalloon(); if (ClickAction!= null) { ClickAction(); } } public Action ClickAction { get; set; } } }