Пример #1
0
        /// <summary>
        /// 点击注销按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void miPrinterLogout_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var collections = Application.Current.Windows;

            foreach (Window window in collections)
            {
                BaseWindow win = window as BaseWindow;
                if (win != null)
                {
                    // 其他Window直接关闭
                    if (win.ToString().Contains("LoginWindow"))
                    {
                        win.Show();
                    }
                    else if (win != this)
                    {
                        // 设置不需要关闭页面提示
                        win.needCloseWindowConfirm = false;
                        win.Close();
                    }
                }
            }
            // 设置不需要关闭页面提示
            this.needCloseWindowConfirm = false;
            CloseCurrentWindow();
        }
Пример #2
0
        public void BaseWindow_Closing(object sender, CancelEventArgs e)
        {
            if (needCloseWindowConfirm)
            {
                if (this.ToString().Contains("MainWindow"))
                {
                    MessageBoxResult result = MessageBox.Show("确定要退出系统吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    //关闭窗口
                    if (result == MessageBoxResult.Yes)
                    {
                        this.Hide();
                        Application.Current.Shutdown();
                        Environment.Exit(0);
                    }
                    return;
                }
                else
                {
                    var collections = Application.Current.Windows;
                    foreach (Window window in collections)
                    {
                        BaseWindow win = window as BaseWindow;
                        if (win != null)
                        {
                            // 其他Window直接关闭
                            if (win.ToString().Contains("MainWindow"))
                            {
                                win.Show();
                            }
                        }
                    }

                    //MessageBoxResult result = MessageBox.Show("确定关闭当前窗口吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    ////关闭窗口
                    //if (result == MessageBoxResult.Yes)
                    //{
                    //    // 打开主窗口
                    //    var collections = Application.Current.Windows;
                    //    foreach (Window window in collections)
                    //    {
                    //        BaseWindow win = window as BaseWindow;
                    //        if (win != null)
                    //        {
                    //            // 其他Window直接关闭
                    //            if (win.ToString().Contains("MainWindow"))
                    //            {
                    //                win.Show();
                    //            }
                    //        }
                    //    }

                    //    e.Cancel = false;
                    //}
                    ////不关闭窗口
                    //if (result == MessageBoxResult.No)
                    //    e.Cancel = true;
                }
            }
        }