WPF Window appear in the lower left foot

duwen 21 Reputation points
2020-09-04T01:47:49.477+00:00

WPF After I set ShowInTaskBar=false for the window, when I hit minimize, I don't want the window to appear in the lower left foot, what do I do

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,192 questions
No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,506 Reputation points
    2020-09-04T06:45:01.407+00:00

    You can use System.Windows.Forms to use NotifyIcon and System.Drawing to use Icon to implement the hidden of minimized window under the taskbar on the right. It looks like below picture shown:
    22694-999.jpg

    To implement it, you need to add the below code to your cs code:

    public partial class MainWindow : Window  
        {  
            NotifyIcon notifyIcon;  
            public MainWindow()  
            {  
                InitializeComponent();  
            }  
      
            private void Window_StateChanged(object sender, EventArgs e)  
            {  
                switch (this.WindowState)  
                {  
                    case WindowState.Maximized:  
                        break;  
                    case WindowState.Minimized:  
                        this.notifyIcon = new NotifyIcon();  
                        notifyIcon.BalloonTipText = "This is WPF app";  
                        notifyIcon.Icon = new System.Drawing.Icon("Todolist.ico");  
                        notifyIcon.Visible = true;  
                        notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;  
                        this.notifyIcon.ShowBalloonTip(1000);  
                        this.Hide();  
                        break;  
                    case WindowState.Normal:  
                        break;  
                }  
            }  
      
            private void OnNotifyIconDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)  
            {  
                this.Show();  
                WindowState = WindowState.Normal;  
            }     
    

1 additional answer

Sort by: Most helpful
  1. Viorel 83,101 Reputation points
    2020-09-04T11:25:49.947+00:00

    If this is a secondary window and you want to hide it, then handle the StateChanged event:

    private void Window_StateChanged( object sender, EventArgs e )
    {
        if( WindowState == WindowState.Minimized)
        {
            Hide( );
        }
    }
    

    You should have a mechanism to re-show it, and to close when the application exits.