WPF Binding with RelativeSource of Window Requires "DataContext" in Path?

Posted by Phil Sandler on Stack Overflow See other posts from Stack Overflow or by Phil Sandler
Published on 2010-03-22T15:19:10Z Indexed on 2010/03/22 15:21 UTC
Read the original article Hit count: 336

Filed under:
|

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>        

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding