我通过弹出窗口向用户显示一些内容。弹出窗口的视图模型有一个" CloseWindowCommand"它的方法如下;
private void CloseWindow()
{
var codeFileViewModels = CodeFileViews.Select(view => GetCodeFileViewModel(view)).Where(viewModel => viewModel.IsDirty);
foreach (var codeFileViewModel in codeFileViewModels)
{
_regionManager.RequestNavigate(
WellKnownRegionNames.CodeFileRegion,
new Uri(WellKnownViewNames.CodeFileView, UriKind.Relative),
navigation =>
{
if (navigation.Result != true)
{
throw new Exception(_languageService.FindResource(WellKnownResourceKeys.CodeFileWindowNavigationFailedMessage));
}
},
new NavigationParameters
{
{WellKnownParameterKeys.FileName, codeFileViewModel.Name}
});
var messageResult = _messageService.ShowYesNoCancelQuestion(null, _languageService.FindResource(WellKnownResourceKeys.DoYouWantToSaveChanges));
if (messageResult == null)
return;
if (messageResult == true)
if (!Save(codeFileViewModel))
return;
}
FinishInteraction?.Invoke();
}
我在一个按钮上绑定此命令,但问题是用户也可以从Windows标准关闭按钮关闭它。如何从弹出窗口的WRAPPER(HOST)WINDOW关闭按钮调用此方法?