我想将一个属性绑定到父容器视图,该视图具有其DataContext中的ViewModel。
当父级是ConcreteClassView的直接实例时,此代码完美地工作:
然而,当尝试通过基类或接口定位时,无法找到该父级。 示例:
考虑到:
好的,让我们假设 FindAncestor、AncestorType需要具体类型才能工作。
但是是否有任何解决方法可以基于基类或实现给定接口来定位祖先元素呢?
谢谢。
当父级是ConcreteClassView的直接实例时,此代码完美地工作:
Property="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ty:ConcreteClassView}}, Path=DataContext.Name}"
然而,当尝试通过基类或接口定位时,无法找到该父级。 示例:
PropertyB="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ty:BaseClassView}}, Path=DataContext.Name}"
PropertyB="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ty:INamedElementView}}, Path=DataContext.Name}"
考虑到:
class ConcreteClassView : BaseClassView, INamedElementView { }
好的,让我们假设 FindAncestor、AncestorType需要具体类型才能工作。
但是是否有任何解决方法可以基于基类或实现给定接口来定位祖先元素呢?
谢谢。
AncestorType
必须与基类一起使用。 - VladINamedElementView
在其他的命名空间里? - Vladty
别名引用了它。 - pjmolina