How can we improve the Windows dev platform?

Ancestor binding missing

Currently the RelativeSourceMode only supports None, TemplatedParent and Self.

Would be really helpful to have FindAncestor API added, just like in Silverlight 5 and WPF.

87 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

Justin Liu shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: facebook google
Signed in as (Sign out)
  • Martin commented  ·   ·  Flag as inappropriate

    Useage Scenarios of RelativeSource:
    (This could also be achieved with ElementName, but requires setting a Name for the TextBox. With the AncetoryType Binding we can just copy/paste the KeyBinding, so we prefer the AncetoryType solution )
    <TextBox KeyboardNavigation.TabIndex="0" MaxLength="12" Text="{Binding Path=OrderNo,UpdateSourceTrigger=PropertyChanged}">
    <KeyBinding Key="Enter" Command="{Binding Path=StartACommand}" CommandParameter="{Binding Path=Text,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type TextBox}}}"/>

    An other example where we use AncestorType:

    <ListView ItemsSource="{Binding Path=List,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
    <Button Content="AText" Command="{Binding DataContext.RemoveCommand,RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
    CommandParameter="{Binding Path=.}" />

Feedback and Knowledge Base