示例#1
0
        private void CreateSystrayIcon()
        {
            if (ProgramSettings.Instance.SystrayDisplay)
            {
                if (MyNotifyIcon == null)
                {
                    try
                    {
                        MyNotifyIcon = new TaskbarIcon()
                        {
                            Name = "MyNotifyIcon",
                            VerticalAlignment = System.Windows.VerticalAlignment.Top,
                            Icon        = new System.Drawing.Icon(Application.GetResourceStream(new Uri("pack://application:,,,/CIV;component/Icons/Application.ico")).Stream),
                            ContextMenu = new ContextMenu()
                        };

                        MyNotifyIcon.DoubleClickCommand          = new DashboardShowCommand();
                        MyNotifyIcon.DoubleClickCommandParameter = this;

                        MyNotifyIcon.SetBinding(Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ToolTipTextProperty,
                                                new Binding("Text.Dashboard_Title")
                        {
                            Source = new CIVResourceManager()
                        });

                        // Menu
                        MenuItem menu = new MenuItem()
                        {
                            Icon = new Image()
                            {
                                Source = new BitmapImage(new Uri("pack://application:,,,/CIV;component/Images/Exit.png", UriKind.RelativeOrAbsolute)),
                                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                                VerticalAlignment   = System.Windows.VerticalAlignment.Center,
                                Stretch             = Stretch.None
                            }
                        };
                        menu.Click += miExit_Click;
                        menu.SetBinding(MenuItem.HeaderProperty,
                                        new Binding("Text.Dashboard_miExit")
                        {
                            Source = new CIVResourceManager()
                        });


                        MyNotifyIcon.ContextMenu.Items.Add(menu);

                        // Contenu
                        Style style = new Style(typeof(ToolTip), null);
                        style.Setters.Add(new Setter(ContentControl.TemplateProperty,
                                                     new ControlTemplate(typeof(ToolTip))
                        {
                            VisualTree = new FrameworkElementFactory(typeof(ContentPresenter))
                        }));

                        ToolTip tip = new ToolTip()
                        {
                            Style   = style,
                            Content = new QuickStats()
                        };

                        MyNotifyIcon.TrayToolTip = tip;
                    }
                    catch (Exception e) { LogEngine.Instance.Add(e, false); }
                }
            }
            else
            {
                if (MyNotifyIcon != null)
                {
                    try
                    {
                        MyNotifyIcon.Icon.Dispose();
                        MyNotifyIcon.Dispose();
                        MyNotifyIcon = null;
                    }
                    catch (Exception e) { LogEngine.Instance.Add(e, false); }
                }
            }
        }
示例#2
0
        private void UpdateUI()
        {
            if (Account.Account.Overcharge > 0)
            {
                imgAlert.Source = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/CIV;component/Images/Alert-User.png"));
                imgAlert.Visibility = System.Windows.Visibility.Visible;
            }
            else
                imgAlert.Visibility = System.Windows.Visibility.Collapsed;

            // Gestion de l'icône dans la barre système
            try
            {
                if (_account.SystrayDisplay)
                {
                    if (MyNotifyIcon == null)
                    {

                        MyNotifyIcon = new TaskbarIcon()
                        {
                            Name = "MyNotifyIcon",
                            VerticalAlignment = System.Windows.VerticalAlignment.Top,
                            ContextMenu = new ContextMenu()
                        };

                        MyNotifyIcon.DoubleClickCommand = new DashboardShowCommand();
                        MyNotifyIcon.DoubleClickCommandParameter = this.Parent;

                        MyNotifyIcon.SetBinding(Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ToolTipTextProperty,
                                                new Binding("Account.DisplayName") { Source = _account });

                        // Menu
                        MenuItem menu = new MenuItem()
                        {
                            Icon = new System.Windows.Controls.Image()
                            {
                                Source = new BitmapImage(new Uri("pack://application:,,,/CIV;component/Images/Exit.png", UriKind.RelativeOrAbsolute)),
                                HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                                VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                Stretch = Stretch.None
                            }
                        };
                    }
                    else
                        MyNotifyIcon.Icon.Dispose();

                    UsagePieChart pie = new UsagePieChart(_account.Account, ProgramSettings.Instance.CombinedColor.GetColor(), System.Drawing.Color.White);
                    MyNotifyIcon.Icon = pie.GenerateIcon();
                }
                else
                {
                    if (MyNotifyIcon != null)
                    {
                        MyNotifyIcon.Icon.Dispose();
                        MyNotifyIcon.Dispose();
                    }
                }
            }
            catch (Exception e) { LogEngine.Instance.Add(e, false); }
        }
示例#3
0
        private void CreateSystrayIcon()
        {
            if (ProgramSettings.Instance.SystrayDisplay)
            {
                if (MyNotifyIcon == null)
                {
                    try
                    {
                        MyNotifyIcon = new TaskbarIcon()
                            {
                                Name = "MyNotifyIcon",
                                VerticalAlignment = System.Windows.VerticalAlignment.Top,
                                Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri("pack://application:,,,/CIV;component/Icons/Application.ico")).Stream),
                                ContextMenu = new ContextMenu()
                            };

                        MyNotifyIcon.DoubleClickCommand = new DashboardShowCommand();
                        MyNotifyIcon.DoubleClickCommandParameter = this;

                        MyNotifyIcon.SetBinding(Hardcodet.Wpf.TaskbarNotification.TaskbarIcon.ToolTipTextProperty,
                                                new Binding("Text.Dashboard_Title") { Source = new CIVResourceManager() });

                        // Menu
                        MenuItem menu = new MenuItem()
                            {
                                Icon = new Image()
                                {
                                    Source = new BitmapImage(new Uri("pack://application:,,,/CIV;component/Images/Exit.png", UriKind.RelativeOrAbsolute)),
                                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                                    Stretch = Stretch.None
                                }
                            };
                        menu.Click += miExit_Click;
                        menu.SetBinding(MenuItem.HeaderProperty,
                                        new Binding("Text.Dashboard_miExit") { Source = new CIVResourceManager() });

                        MyNotifyIcon.ContextMenu.Items.Add(menu);

                        // Contenu
                        Style style = new Style(typeof(ToolTip), null);
                        style.Setters.Add(new Setter(ContentControl.TemplateProperty,
                                          new ControlTemplate(typeof(ToolTip)) { VisualTree = new FrameworkElementFactory(typeof(ContentPresenter)) }));

                        ToolTip tip = new ToolTip()
                            {
                                Style = style,
                                Content = new QuickStats()
                            };

                        MyNotifyIcon.TrayToolTip = tip;

                    }
                    catch (Exception e) { LogEngine.Instance.Add(e, false); }
                }
            }
            else
            {
                if (MyNotifyIcon != null)
                {
                    try
                    {
                        MyNotifyIcon.Icon.Dispose();
                        MyNotifyIcon.Dispose();
                        MyNotifyIcon = null;
                    }
                    catch (Exception e) { LogEngine.Instance.Add(e, false); }
                }
            }
        }