private static WorkspaceWindow GetWindow(TabItem item) { if (item != null) { return(WorkspaceWindow.GetWorkspaceWindow(item.Content as FrameworkElement)); } return(null); }
private static void OnCloseWorkspaceWindowCommandExecuted(object sender, ExecutedRoutedEventArgs e) { //如果是 windows 触发的命令,那么应该关闭当前窗口。 //如果是其它界面元素触发的命令,则命令的参数就是需要关闭的窗口元素。 var ws = App.Current.Workspace; var windowControl = e.Parameter as FrameworkElement; WorkspaceWindow window = null; if (windowControl != null) { window = WorkspaceWindow.GetWorkspaceWindow(windowControl); } else { window = ws.ActiveWindow; } if (window != null) { ws.TryRemove(window); } }