mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-01-20 17:29:04 -05:00
WPF NotifyIcon
-------------- ADD Added ParentTaskbarIcon attached dependency property which is set for tooltips, popups, and custom balloons. CHG Made CloseBalloon public. CHG Changed sample, cleaned up commands pattern. git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@93 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
64
Source/Sample Project/Commands/CommandBase.cs
Normal file
64
Source/Sample Project/Commands/CommandBase.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace Sample_Project.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic implementation of the <see cref="ICommand"/>
|
||||
/// interface, which is also accessible as a markup
|
||||
/// extension.
|
||||
/// </summary>
|
||||
public abstract class CommandBase<T> : MarkupExtension, ICommand
|
||||
where T : class, ICommand, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// A singleton instance.
|
||||
/// </summary>
|
||||
private static T command;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a shared command instance.
|
||||
/// </summary>
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (command == null) command = new T();
|
||||
return command;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires when changes occur that affect whether
|
||||
/// or not the command should execute.
|
||||
/// </summary>
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the method to be called when the command is invoked.
|
||||
/// </summary>
|
||||
/// <param name="parameter">Data used by the command.
|
||||
/// If the command does not require data to be passed,
|
||||
/// this object can be set to null.
|
||||
/// </param>
|
||||
public abstract void Execute(object parameter);
|
||||
|
||||
/// <summary>
|
||||
/// Defines the method that determines whether the command
|
||||
/// can execute in its current state.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// This default implementation always returns true.
|
||||
/// </returns>
|
||||
/// <param name="parameter">Data used by the command.
|
||||
/// If the command does not require data to be passed,
|
||||
/// this object can be set to null.
|
||||
/// </param>
|
||||
public virtual bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Sample_Project.Commands
|
||||
@@ -10,30 +6,21 @@ namespace Sample_Project.Commands
|
||||
/// <summary>
|
||||
/// Hides the main window.
|
||||
/// </summary>
|
||||
public class HideMainWindowCommand : ICommand
|
||||
public class HideMainWindowCommand : CommandBase<HideMainWindowCommand>
|
||||
{
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter)
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
Application.Current.MainWindow.Hide();
|
||||
TaskbarIconCommands.RefreshCommands();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
return Application.Current.MainWindow.IsVisible;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="CanExecuteChanged"/> event.
|
||||
/// </summary>
|
||||
internal void RaiseCanExcecuteChanged()
|
||||
{
|
||||
if (CanExecuteChanged != null) CanExecuteChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
@@ -10,29 +9,19 @@ namespace Sample_Project.Commands
|
||||
/// <summary>
|
||||
/// Shows the main window.
|
||||
/// </summary>
|
||||
public class ShowMainWindowCommand : ICommand
|
||||
public class ShowMainWindowCommand : CommandBase<ShowMainWindowCommand>
|
||||
{
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public void Execute(object parameter)
|
||||
public override void Execute(object parameter)
|
||||
{
|
||||
Application.Current.MainWindow.Show();
|
||||
TaskbarIconCommands.RefreshCommands();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
public override bool CanExecute(object parameter)
|
||||
{
|
||||
return Application.Current.MainWindow.IsVisible == false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="CanExecuteChanged"/> event.
|
||||
/// </summary>
|
||||
internal void RaiseCanExcecuteChanged()
|
||||
{
|
||||
if (CanExecuteChanged != null) CanExecuteChanged(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Sample_Project.Commands
|
||||
{
|
||||
public static class TaskbarIconCommands
|
||||
{
|
||||
public static HideMainWindowCommand HideMain { get; set; }
|
||||
public static ShowMainWindowCommand ShowMain { get; set; }
|
||||
|
||||
|
||||
static TaskbarIconCommands()
|
||||
{
|
||||
HideMain = new HideMainWindowCommand();
|
||||
ShowMain =new ShowMainWindowCommand();
|
||||
}
|
||||
|
||||
public static void RefreshCommands()
|
||||
{
|
||||
HideMain.RaiseCanExcecuteChanged();
|
||||
ShowMain.RaiseCanExcecuteChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user