-1

我有一个PrismCore MVVM 应用程序,它重用了一些视图,例如CustomerView最初, CustomerView 在MainWindowView中显示为“图块” 。当用户单击它时 -Window使用我的 WindowService 在新中打开该 CustomerView 的新实例。CustomerView 有一个菜单。我想要什么:如果 CustomerView 显示在 MainWindowView 的“平铺”中 - 菜单应该被隐藏;如果在另一个不同的Window- 菜单应该是可见的。目前,我已经通过代码隐藏完成了这项工作。是否有可能有一个Converter,如果 CustomerView 是 MainWindowView 的一部分,或者其他一些Window

4

1 回答 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 回答