如何在文档组(DevExpress WPF mvvm)中获取活动的选项卡或浮动文档?

时间:2015-07-21 00:26:15

标签: c# wpf mvvm devexpress

我又来了:) 我为应用程序创建了全局Escape快捷方式。它从全局钩子实现,并在DomainModelContext(来自脚手架向导的主UserControl)中发送关闭消息。我尝试不好 - 使用代码隐藏。 我用DockLayoutManager.DockController.Close(DockLayoutManager.ActiveDockItem) 对于关闭选项卡,但其方法关闭一切,包括LayoutPanel :( 我如何使用选项卡式和浮动文档实现关闭活动文档。

在文档下,我指的是从SingleObjectViewModel继承的View或者手动取消停靠的那些

1 个答案:

答案 0 :(得分:1)

完成任务的正确方法是在View Model级别处理CloseMessage(我相信DomainModelContextViewModel)。
在此级别,您可以使用IDocumentManagerService的API:

void OnCloseMessage() {
    var activeDocument = DocumentManagerService.ActiveDocument;
    if(activeDocument != null)
        activeDocument.Close();
}

注意:IDocumentManagerServiceTabbedDocumentUIService)的具体实施应在DomainModelContextView内注册。