2012-04-19 13 views

Respuesta

46

Example in MSDN forum

Aquí está un ejemplo rápido para mostrar cómo minimizar el área de notificación. Debe agregar referencias a los ensamblados System.Window.Forms y System.Drawing.

public partial class Window1 : System.Windows.Window 
{ 

    public Window1() 
    { 
     InitializeComponent(); 

     System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); 
     ni.Icon = new System.Drawing.Icon("Main.ico"); 
     ni.Visible = true; 
     ni.DoubleClick += 
      delegate(object sender, EventArgs args) 
      { 
       this.Show(); 
       this.WindowState = WindowState.Normal; 
      }; 
    } 

    protected override void OnStateChanged(EventArgs e) 
    { 
     if (WindowState == System.Windows.WindowState.Minimized) 
      this.Hide(); 

     base.OnStateChanged(e); 
    } 
} 
+0

¿Tengo que tener un ícono llamado "Main.ico" en mi ApplicationDirectory? –

+0

LeGrandMere - gracias por la excelente solución succint. Félix D: Puede agregar Icon usando: var iconStream = Application.GetResourceStream (nuevo Uri ("paquete: // aplicación: ,,,/LaunchPad.UI; componente/Images/Launch.ico"))? Stream; a continuación, var var = nuevo NotifyIcon { Icono = nuevo icono (iconStream), Visible = verdadero }; – yonsk

9

Tuve éxito al utilizar esta implementación gratuita de icono de notificación en WPF.

http://www.hardcodet.net/projects/wpf-notifyicon

Es bastante simple de instalar y se proporciona el código fuente. No depende de Windows Forms, por lo que es WPF 'puro' y muy personalizable.

Puede encontrar un tutorial sobre cómo usarlo en CodeProject.

5

Agregue notifyIcon a su App from Toolbox.
Seleccione su principal form >> vaya a Properties >> seleccione Events icono >> debajo de FromClosing event tipo MainForm_FormClosing >> pulse enter.

enter image description here

En abierto archivo .cs entran siguiente acción del evento:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    this.Hide(); 
    notifyIcon.Visible = true; 
    ShowInTaskbar = false; 
    e.Cancel = true; 
} 

Ahora su ventana principal formulario se minimiza en la bandeja del sistema cuando se hace clic en el botón X. El siguiente paso es volver a FORMULAR al estado normal.
Vaya a Properties de su notifyIcon >> encuentre DoubleClick event >> escriba NotifyIcon_DoubleClick y pulse enter para obtener la función de evento creada para usted.

enter image description here

poner este código a su evento:

private void NotifyIcon_DoubleClick(object sender, EventArgs e) 
{ 
    this.Show(); 
    notifyIcon.Visible = false; 
} 

Ahora, si usted quiere hacer el icono de notificar en el estilo de fantasía puede agregar menú contextual y vincularlo con el icono de notificar , para que pueda obtener algo así:

enter image description here

Aquí es cuando planees volver a vincular ContextMenuStrip NotifyIcon:

enter image description here

Buena suerte!

+0

Me parece que está describiendo Windows Forms en lugar de WPF. –

Cuestiones relacionadas