下面的代码可以工作,但是我想知道为什么需要在路径前面加上“DataContext”?在大多数其他情况下,使用的路径都是相对于DataContext的。这是因为我使用了RelativeSource吗?因为源位于根级别(Window)?
<Style TargetType="TextBox">
<Setter
Property="IsReadOnly"
Value="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.IsReadOnly}"/>
</Style>