コード例 #1
0
        /// <summary>
        /// 关闭当前用户控件。
        /// </summary>
        public void CloseCurrentContent()
        {
            if (ContentQueue.Count < 2)
            {
                return;
            }

            bool confirm = ConfigurationService.Get(BundleActivator.Bundle, "ConfirmClosingWindow", true);

            if (confirm && ModernDialog.ShowMessage(
                    "你确实是否要关闭当前窗口?",
                    "关闭窗口",
                    MessageBoxButton.YesNo) != MessageBoxResult.Yes)
            {
                return;
            }

            HideSidebar();

            // 删除当前显示的控件,即最后一个
            var content = ContentQueue[ContentQueue.Count - 1];

            ContentQueue.Remove(content);
            // 删除缓存
            var key = string.Empty;

            foreach (var pair in OpenedPagesCache)
            {
                if (pair.Value.Equals(content))
                {
                    key = pair.Key;
                }
            }
            if (!string.IsNullOrEmpty(key))
            {
                OpenedPagesCache.Remove(key);
            }

            // 从容器中删除该控件
            LayoutDockPanel.Children.Remove(content);
            // 显示倒数第二个用户控件
            ShowContent(ContentQueue[ContentQueue.Count - 1]);

            if (TreeViewItemSelectionQueue.Count > 0) // 设置当前节点选中状态为false,并且删除其选中队列
            {
                (TreeViewItemSelectionQueue[TreeViewItemSelectionQueue.Count - 1] as TreeViewItem).IsSelected = false;
                TreeViewItemSelectionQueue.RemoveAt(TreeViewItemSelectionQueue.Count - 1);
            }
            if (TreeViewItemSelectionQueue.Count > 0) // 选中前一个节点
            {
                (TreeViewItemSelectionQueue[TreeViewItemSelectionQueue.Count - 1] as TreeViewItem).IsSelected = true;
            }
        }