我有一个Prism
Core MVVM 应用程序,它重用了一些视图,例如CustomerView。最初, CustomerView 在MainWindowView中显示为“图块” 。当用户单击它时 -Window
使用我的 WindowService 在新中打开该 CustomerView 的新实例。CustomerView 有一个菜单。我想要什么:如果 CustomerView 显示在 MainWindowView 的“平铺”中 - 菜单应该被隐藏;如果在另一个不同的Window
- 菜单应该是可见的。目前,我已经通过代码隐藏完成了这项工作。是否有可能有一个Converter
,如果 CustomerView 是 MainWindowView 的一部分,或者其他一些Window
?
1 回答
1
您可以绑定到CustomerView
自身并使用尝试MainWindowView
在可视化树中查找父级的辅助方法:
public static T FindParent<T>(DependencyObject dependencyObject) where T : DependencyObject
{
var parent = VisualTreeHelper.GetParent(dependencyObject);
if (parent == null) return null;
var parentT = parent as T;
return parentT ?? FindParent<T>(parent);
}
用法:
MainWindowView parent = FindParent<MainWindowView>(customerView);
if (parent != null)
//MainWindowView found...
于 2019-12-09T12:54:18.217 回答