Notifyicon beim Minimieren | WPF | C#

08/26/2016 22:11 Entonsammler#1
Bräuchte Hilfe bei einem Notifyicon welches sich beim Minimieren des Fenstern öffnen soll, und beim anklicken das Fenster öffnen soll und dann wieder verschwindet :confused: .

Bin grad total verwirrt von dem Zeugs :confused: .
08/27/2016 05:32 atom0s#2
You can use the following with your main window:

PHP Code:
namespace YourApplicationName.View
{
    
using System;
    
using System.Windows;
    
using System.Windows.Forms;

    
/// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    
public partial class MainWindow
    
{
        
/// <summary>
        /// Notification icon object.
        /// </summary>
        
private readonly NotifyIcon m_NotifyIcon;


        
/// <summary>
        /// Default Constructor
        /// </summary>
        
public MainWindow()
        {
            
this.InitializeComponent();


            try
            {
                
// Attempt to obtain the icon stream..
                
var iconUri = new Uri("/YourApplicationName;component/Assets/appicon.ico"UriKind.RelativeOrAbsolute);
                var 
iconStream System.Windows.Application.GetResourceStream(iconUri);
                if (
iconStream == null)
                    return;


                
// Prepare the notify icon..
                
this.m_NotifyIcon = new NotifyIcon
                
{
                    
Icon = new System.Drawing.Icon(iconStream.Stream),
                    
Text "YourApplicationName",
                    
Visible true
                
};


                
// Handle double click event..
                
this.m_NotifyIcon.MouseDoubleClick += (senderargs) =>
                {
                    
this.WindowState this.WindowState == WindowState.Normal WindowState.Minimized WindowState.Normal;
                    
this.ShowInTaskbar this.WindowState != WindowState.Minimized;
                };


                
// Register to window events..
                
this.Closed += this.OnClosed;
                
this.StateChanged += this.OnStateChanged;
            }
            catch (
Exception)
            {
            }
        }


        
/// <summary>
        /// Closed event callback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
private void OnClosed(object senderEventArgs e)
        {
            if (
this.m_NotifyIcon != null)
            {
                
this.m_NotifyIcon.Visible false;
                
this.m_NotifyIcon.Dispose();
            }
        }


        
/// <summary>
        /// StateChanged event callback.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
private void OnStateChanged(object senderEventArgs e)
        {
            
// Handle minimized state changes for tray icon..
            
if (this.m_NotifyIcon != null)
                
this.ShowInTaskbar this.WindowState != WindowState.Minimized;
        }
    }

08/27/2016 09:49 Entonsammler#3
thanks but i'm using a WPF not a windows Form:(
08/27/2016 20:07 Njahs#4
Quote:
Originally Posted by Themanwhoisit View Post
thanks but i'm using a WPF not a windows Form:(
[Only registered and activated users can see links. Click Here To Register...] befindet sich im [Only registered and activated users can see links. Click Here To Register...] Namespace.

Eine Alternative für WPF wäre [Only registered and activated users can see links. Click Here To Register...].

Grüße
08/28/2016 21:14 atom0s#5
Quote:
Originally Posted by Themanwhoisit View Post
thanks but i'm using a WPF not a windows Form:(
That code is for WPF.