2012-08-25 46 views

回答

3

想要MyAttachedProp.Value拥有Window对象引用吗?

您可以使用任何这些方法:

  1. {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}

  2. 给你的窗口的X:名称= “XXXXX” ......然后用{Binding ElementName=XXXXX}找到它。

  3. {Binding RelativeSource={RelativeSource Self}}

  4. {Binding RelativeSource={x:Static RelativeSource.Self}}

用实施例4中,它避免了新RelativeSource对象(与Mode设置为Self)的创建...代替它指向的静态一个已经创建在RelativeSource类....(这是一个非常小的和过早的优化)。

大多数人使用示例3,因为它更少输入和更清晰地阅读。

1

{Binding RelativeSource={RelativeSource Self}}