From 19f4f8717ca2019eed35a35606af4a28f6048ea6 Mon Sep 17 00:00:00 2001 From: Philipp Sumi Date: Sun, 17 Nov 2013 23:47:44 +0000 Subject: [PATCH] CHG Better ContextMenu tutorial sample. git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@187 9f600761-6f11-4665-b6dc-0185e9171623 --- .../InlineContextMenuWindow.xaml | 96 ++++++++++++++----- .../InlineContextMenuWindow.xaml.cs | 59 ++++++------ 2 files changed, 106 insertions(+), 49 deletions(-) diff --git a/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml b/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml index 7338e68..a5e8da1 100644 --- a/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml +++ b/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml @@ -1,27 +1,79 @@ - - + + - + - - - - - - - + + + + + + + + + + - - + - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml.cs b/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml.cs index fea9324..6c156b5 100644 --- a/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml.cs +++ b/Source/Sample Project/Tutorials/04 - ContextMenus/InlineContextMenuWindow.xaml.cs @@ -1,35 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Diagnostics; 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.Shapes; namespace Samples.Tutorials.ContextMenus { - /// - /// Interaction logic for InlineContextMenuWindow.xaml - /// - public partial class InlineContextMenuWindow : Window - { - public InlineContextMenuWindow() + /// + /// Interaction logic for InlineContextMenuWindow.xaml + /// + public partial class InlineContextMenuWindow : Window { - InitializeComponent(); + public InlineContextMenuWindow() + { + InitializeComponent(); + } + + + protected override void OnClosing(System.ComponentModel.CancelEventArgs e) + { + //clean up notifyicon (would otherwise stay open until application finishes) + MyNotifyIcon.Dispose(); + + base.OnClosing(e); + } + + private void MyNotifyIcon_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + OpenEventCounter.Text = (int.Parse(OpenEventCounter.Text) + 1).ToString(); + } + + private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + //marking the event as handled suppresses the context menu + e.Handled = (bool)SuppressContextMenu.IsChecked; + + PreviewOpenEventCounter.Text = (int.Parse(PreviewOpenEventCounter.Text) + 1).ToString(); + } } - - - protected override void OnClosing(System.ComponentModel.CancelEventArgs e) - { - //clean up notifyicon (would otherwise stay open until application finishes) - MyNotifyIcon.Dispose(); - - base.OnClosing(e); - } - } -} +} \ No newline at end of file