查找与我的 ViewModel 关联的视图的所有者

Find the owner of the View associated to my ViewModel

我正在实施 IDialogService。这将从我的 ViewModel 调用,它不知道 View。

推断 所有者ShowDialog 的最佳方法是什么?

如果我能避免注册哪个 View 绑定到哪个 ViewModel 就好了。

如果有帮助,我正在使用 Prism(v6)。

你可以试试这个:

window.Owner = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);