From 26e8db45dae0e71b5ecb8a34b0e107becf0a8a73 Mon Sep 17 00:00:00 2001 From: Philipp Sumi Date: Sat, 23 Nov 2013 02:10:17 +0000 Subject: [PATCH] ADD Sample for windowless application. NTFY-25 git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@203 9f600761-6f11-4665-b6dc-0185e9171623 --- Source/Windowless Sample/App.xaml | 21 ++++ Source/Windowless Sample/App.xaml.cs | 27 +++++ Source/Windowless Sample/MainWindow.xaml | 8 ++ Source/Windowless Sample/MainWindow.xaml.cs | 28 +++++ .../NotifyIconResources.xaml | 32 ++++++ .../Windowless Sample/NotifyIconViewModel.cs | 86 +++++++++++++++ .../Properties/AssemblyInfo.cs | 55 ++++++++++ Source/Windowless Sample/Red.ico | Bin 0 -> 1150 bytes .../Windowless Sample.csproj | 98 ++++++++++++++++++ 9 files changed, 355 insertions(+) create mode 100644 Source/Windowless Sample/App.xaml create mode 100644 Source/Windowless Sample/App.xaml.cs create mode 100644 Source/Windowless Sample/MainWindow.xaml create mode 100644 Source/Windowless Sample/MainWindow.xaml.cs create mode 100644 Source/Windowless Sample/NotifyIconResources.xaml create mode 100644 Source/Windowless Sample/NotifyIconViewModel.cs create mode 100644 Source/Windowless Sample/Properties/AssemblyInfo.cs create mode 100644 Source/Windowless Sample/Red.ico create mode 100644 Source/Windowless Sample/Windowless Sample.csproj diff --git a/Source/Windowless Sample/App.xaml b/Source/Windowless Sample/App.xaml new file mode 100644 index 0000000..5417c0a --- /dev/null +++ b/Source/Windowless Sample/App.xaml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + diff --git a/Source/Windowless Sample/App.xaml.cs b/Source/Windowless Sample/App.xaml.cs new file mode 100644 index 0000000..e36f2e6 --- /dev/null +++ b/Source/Windowless Sample/App.xaml.cs @@ -0,0 +1,27 @@ +using System.Windows; +using Hardcodet.Wpf.TaskbarNotification; + +namespace Windowless_Sample +{ + /// + /// Simple application. Check the XAML for comments. + /// + public partial class App : Application + { + private TaskbarIcon notifyIcon; + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + //create the notifyicon (it's a resource declared in NotifyIconResources.xaml + notifyIcon = (TaskbarIcon) FindResource("NotifyIcon"); + } + + protected override void OnExit(ExitEventArgs e) + { + notifyIcon.Dispose(); //the icon would clean up automatically, but this is cleaner + base.OnExit(e); + } + } +} diff --git a/Source/Windowless Sample/MainWindow.xaml b/Source/Windowless Sample/MainWindow.xaml new file mode 100644 index 0000000..9937fb3 --- /dev/null +++ b/Source/Windowless Sample/MainWindow.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/Source/Windowless Sample/MainWindow.xaml.cs b/Source/Windowless Sample/MainWindow.xaml.cs new file mode 100644 index 0000000..fe76599 --- /dev/null +++ b/Source/Windowless Sample/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +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; + +namespace Windowless_Sample +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/Source/Windowless Sample/NotifyIconResources.xaml b/Source/Windowless Sample/NotifyIconResources.xaml new file mode 100644 index 0000000..66ea812 --- /dev/null +++ b/Source/Windowless Sample/NotifyIconResources.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Windowless Sample/NotifyIconViewModel.cs b/Source/Windowless Sample/NotifyIconViewModel.cs new file mode 100644 index 0000000..a7e8fc3 --- /dev/null +++ b/Source/Windowless Sample/NotifyIconViewModel.cs @@ -0,0 +1,86 @@ +using System; +using System.Windows; +using System.Windows.Input; + +namespace Windowless_Sample +{ + /// + /// Provides bindable properties and commands for the NotifyIcon. In this sample, the + /// view model is assigned to the NotifyIcon in XAML. Alternatively, the startup routing + /// in App.xaml.cs could have created this view model, and assigned it to the NotifyIcon. + /// + public class NotifyIconViewModel + { + /// + /// Shows a window, if none is already open. + /// + public ICommand ShowWindowCommand + { + get + { + return new DelegateCommand + { + CanExecuteFunc = () => Application.Current.MainWindow == null, + CommandAction = () => + { + Application.Current.MainWindow = new MainWindow(); + Application.Current.MainWindow.Show(); + } + }; + } + } + + /// + /// Hides the main window. This command is only enabled if a window is open. + /// + public ICommand HideWindowCommand + { + get + { + return new DelegateCommand + { + CommandAction = () => Application.Current.MainWindow.Close(), + CanExecuteFunc = () => Application.Current.MainWindow != null + }; + } + } + + + /// + /// Shuts down the application. + /// + public ICommand ExitApplicationCommand + { + get + { + return new DelegateCommand {CommandAction = () => Application.Current.Shutdown()}; + } + } + } + + + /// + /// Simplistic delegate command for the demo. + /// + public class DelegateCommand : ICommand + { + public Action CommandAction { get; set; } + public Func CanExecuteFunc { get; set; } + + public void Execute(object parameter) + { + CommandAction(); + } + + public bool CanExecute(object parameter) + { + return CanExecuteFunc == null || CanExecuteFunc(); + } + + public event EventHandler CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + } +} diff --git a/Source/Windowless Sample/Properties/AssemblyInfo.cs b/Source/Windowless Sample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ee1de76 --- /dev/null +++ b/Source/Windowless Sample/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Windowless Sample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Windowless Sample")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Source/Windowless Sample/Red.ico b/Source/Windowless Sample/Red.ico new file mode 100644 index 0000000000000000000000000000000000000000..8a8bbafa87909fb28ea0375bf2347fa3d3768d26 GIT binary patch literal 1150 zcmdUt%_~G<6vm%BKFj24$Ye1nDLZzSn$4`Sq=_uBLnK+Tk-x%DlDiP4?8KThtdLmv z3Xvk&9MALK!Ocgq^iIE-XU=)fIq&=43wZogRDj?07%T*;0W=YY7zyM2`OETXj*)^q z(u)1ImHo|)-07WD=jrkCPU(J zv)WqqSR?YdN28jzC7l39)`3-e&d4><%m?yFF31XzM_%`QqV=3VbftRV-?c>IfE<%k zhwtZDtKRZ_JD=z8zbr4;{6>vdPr{p&7@f!^hYhI#Ah$=TT0 zp=Gl + + + + Debug + AnyCPU + {964EBFBE-A600-49B2-BDD8-422B46F1D544} + WinExe + Properties + Windowless_Sample + Windowless Sample + v4.0 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + Designer + MSBuild:Compile + + + + + + Code + + + + + + {7AC63864-7638-41C4-969C-D3197EF2BED9} + NotifyIconWpf + + + + + + + + \ No newline at end of file