mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-02-17 02:51:51 -05:00
CHG Better ContextMenu tutorial sample.
git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@187 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
@@ -1,27 +1,79 @@
|
|||||||
<Window
|
<Window x:Class="Samples.Tutorials.ContextMenus.InlineContextMenuWindow"
|
||||||
x:Class="Samples.Tutorials.ContextMenus.InlineContextMenuWindow"
|
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||||
|
xmlns:commands="clr-namespace:Samples.Commands"
|
||||||
Height="300"
|
Height="300"
|
||||||
Width="300">
|
Width="300">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
||||||
<tb:TaskbarIcon
|
<tb:TaskbarIcon x:Name="MyNotifyIcon"
|
||||||
x:Name="MyNotifyIcon"
|
|
||||||
IconSource="/Icons/Error.ico"
|
IconSource="/Icons/Error.ico"
|
||||||
ToolTipText="hello world">
|
ToolTipText="hello world"
|
||||||
|
TrayContextMenuOpen="MyNotifyIcon_TrayContextMenuOpen"
|
||||||
|
PreviewTrayContextMenuOpen="MyNotifyIcon_PreviewTrayContextMenuOpen">
|
||||||
|
|
||||||
<!-- Set a simple context menu -->
|
<!-- Set a simple context menu -->
|
||||||
|
<!-- the data context of the context menu is the NotifyIcon itself (see more about this in DataBinding samples) -->
|
||||||
<tb:TaskbarIcon.ContextMenu>
|
<tb:TaskbarIcon.ContextMenu>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<MenuItem Header="First Menu Item" />
|
<TextBlock Text="Hiding the sample window will not close it!" />
|
||||||
<MenuItem Header="Second Menu Item" />
|
<MenuItem Header="_Show Sample Window [S]"
|
||||||
|
Command="{commands:ShowSampleWindowCommand}"
|
||||||
|
CommandParameter="{Binding}">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<Image Width="16"
|
||||||
|
Height="16"
|
||||||
|
Source="/Images/Add.png" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
|
<Separator />
|
||||||
|
|
||||||
|
<MenuItem Header="_Hide Sample Window [H]"
|
||||||
|
Command="{commands:HideSampleWindowCommand}"
|
||||||
|
CommandParameter="{Binding}">
|
||||||
|
<MenuItem.Icon>
|
||||||
|
<Image Width="16"
|
||||||
|
Height="16"
|
||||||
|
Source="/Images/Remove.png" />
|
||||||
|
</MenuItem.Icon>
|
||||||
|
</MenuItem>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</tb:TaskbarIcon.ContextMenu>
|
</tb:TaskbarIcon.ContextMenu>
|
||||||
|
|
||||||
</tb:TaskbarIcon>
|
</tb:TaskbarIcon>
|
||||||
<TextBlock Margin="26,26,24,0" VerticalAlignment="Top" FontWeight="Bold" TextWrapping="Wrap"><Run Language="de-ch" Text="Right-click on NotifyIcon to open Context Menu"/></TextBlock>
|
<TextBlock Margin="26,26,24,0"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
FontWeight="Bold"
|
||||||
|
TextWrapping="Wrap"><Run Language="de-ch"
|
||||||
|
Text="Right-click on NotifyIcon to open Context Menu" /></TextBlock>
|
||||||
|
<TextBlock HorizontalAlignment="Left"
|
||||||
|
Margin="26,83,0,0"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Text="Context menu preview open events:"
|
||||||
|
VerticalAlignment="Top" />
|
||||||
|
<TextBlock HorizontalAlignment="Left"
|
||||||
|
Margin="26,103.96,0,0"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Text="Context menu open events:"
|
||||||
|
VerticalAlignment="Top" />
|
||||||
|
<TextBlock x:Name="PreviewOpenEventCounter"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Margin="246,83,0,0"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Text="0"
|
||||||
|
VerticalAlignment="Top" />
|
||||||
|
<TextBlock x:Name="OpenEventCounter"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Margin="246,106.97,0,0"
|
||||||
|
TextWrapping="Wrap"
|
||||||
|
Text="0"
|
||||||
|
VerticalAlignment="Top" />
|
||||||
|
<CheckBox x:Name="SuppressContextMenu"
|
||||||
|
Content="Suppress context menu in preview event"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Margin="26,190,0,0"
|
||||||
|
VerticalAlignment="Top" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
using System;
|
using System.Diagnostics;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Shapes;
|
|
||||||
|
|
||||||
namespace Samples.Tutorials.ContextMenus
|
namespace Samples.Tutorials.ContextMenus
|
||||||
{
|
{
|
||||||
@@ -31,5 +23,18 @@ namespace Samples.Tutorials.ContextMenus
|
|||||||
|
|
||||||
base.OnClosing(e);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user