private void ChromelessWindow_Loaded(object sender, RoutedEventArgs e)
{
defaults.ShowInTaskBar = true;
System.Windows.Media.Imaging.BitmapImage bim = new System.Windows.Media.Imaging.BitmapImage();
bim.BeginInit();
bim.DecodePixelWidth = 16;
bim.UriSource = new Uri("pack://application:,,,/NotifyIcon_2008;Component/Icon.ico");
bim.EndInit();
defaults.Icon = bim;
defaults.MouseRightButtonDown += Defaults_MouseRightButtonDown;
}
private void Defaults_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
ContextMenu contextMenu = new ContextMenu();
contextMenu.Items.Add(new MenuItem() { Header = "Balloon" });
contextMenu.Items.Add(new MenuItem() { Header = "Rectangle" });
contextMenu.Items.Add(new MenuItem() { Header = "RoundedRectangle" });
contextMenu.PlacementTarget = sender as NotifyIcon;
contextMenu.Items.Cast<MenuItem>().ToList().ForEach(x => x.Click += X_Click);
contextMenu.IsOpen = true;
}
private void X_Click(object sender, RoutedEventArgs e)
{
var menuItem = e.OriginalSource as MenuItem;
if(menuItem != null)
{
switch (menuItem.Header.ToString())
{
case "Balloon":
defaults.BalloonTipShape = BalloonTipShapes.Balloon;
break;
case "Rectangle":
defaults.BalloonTipShape = BalloonTipShapes.Rectangle;
break;
case "RoundedRectangle":
defaults.BalloonTipShape = BalloonTipShapes.RoundedRectangle;
break;
}
}
} |
[C#]
private void Defaults_MouseLeftButtonDown(object sender, MouseButtonEventArgse)
{
if(e.ChangedButton == MouseButton.Left)
contextMenu.IsOpen = false;
} |