Minimizing/Closing Application to system tray using WPF

前端 未结 2 1045
情话喂你
情话喂你 2021-02-05 19:31

I want to add application in System Tray when user minimize or close the form. I have done it for the Minimize case. Can anyone tell me that how i can keep my app running and ad

2条回答
  •  无人及你
    2021-02-05 19:58

    You need not use OnStateChanged(). Instead, use the PreviewClosed event.

    public MainWindow()
    {
        ...
        PreviewClosed += OnPreviewClosed;
    }
    
    private void OnPreviewClosed(object sender, WindowPreviewClosedEventArgs e)
    {
        m_savedState = WindowState;
        Hide();
        e.Cancel = true;
    }
    

提交回复
热议问题