WPF Binding with RelativeSource of Window Requires "DataContext" in Path?
- by Phil Sandler
The following code works, but I'm curious as to why I need the Path to be prefixed with "DataContext"? In most other cases, the path used is relative to DataContext. Is it because I am using a RelativeSource? Because the source is at the root level (Window)?
<Style TargetType="TextBox">
<Setter
Property="IsReadOnly"
Value="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}, Path=DataContext.IsReadOnly}"/>
</Style>